2015-11-19 18 views
5

Czy można używać mojego skryptu jQuery w arkuszu kalkulacyjnym Excel? Próbuję użyć geolokalizacji, aby mieć funkcję automatycznego uzupełniania adresu. Mogę to zrobić za pomocą html. http://jsfiddle.net/bobrierton/13ffw6ko/ Ale jestem ciekawy, jak mogę osiągnąć ten sam cel w arkuszu excel.Uruchamianie skryptów geolokalizacji JQuery w Arkuszach kalkulacyjnych programu Excel

Chcę, aby kolumny w arkuszu kalkulacyjnym były następujące: adres, miasto, województwo, kod pocztowy, a następnie za każdym razem, gdy kliknięto w adres Chcę, aby został wypełniony i podał zalecenia, takie jak moja wersja html.

Czy ktoś może pomóc w tym, w jaki sposób jest to możliwe.

var placeSearch, autocomplete; 
 
var componentForm = { 
 
    route: 'long_name', 
 
    locality: 'long_name', 
 
    administrative_area_level_1: 'short_name', 
 
    postal_code: 'short_name' 
 
}; 
 

 
function initialize() { 
 
    // Create the autocomplete object, restricting the search 
 
    // to geographical location types. 
 
    autocomplete = new google.maps.places.Autocomplete(
 
    /** @type {HTMLInputElement} */ 
 
    (document.getElementById('autocomplete')), { 
 
     types: ['geocode'] 
 
    }); 
 
    // When the user selects an address from the dropdown, 
 
    // populate the address fields in the form. 
 
    google.maps.event.addListener(autocomplete, 'place_changed', function() { 
 
    fillInAddress(); 
 
    }); 
 
} 
 

 
// [START region_fillform] 
 
function fillInAddress() { 
 
    // Get the place details from the autocomplete object. 
 
    var place = autocomplete.getPlace(); 
 

 
    for (var component in componentForm) { 
 
    document.getElementById(component).value = ''; 
 
    document.getElementById(component).disabled = false; 
 
    } 
 

 
    // Get each component of the address from the place details 
 
    // and fill the corresponding field on the form. 
 
    for (var i = 0; i < place.address_components.length; i++) { 
 
    var addressType = place.address_components[i].types[0]; 
 
    if (componentForm[addressType]) { 
 
     var val = place.address_components[i][componentForm[addressType]]; 
 
     document.getElementById(addressType).value = val; 
 
    } 
 
    } 
 
    //var keys=[];for (var key in place.address_components[0]) keys.push(key); 
 
    //alert(keys): 
 
    document.getElementById('autocomplete').value = 
 
    place.address_components[0]['long_name'] + ' ' + 
 
    place.address_components[1]['long_name']; 
 
    
 
    /*document.getElementById('route').value = (document.getElementById('chbSame').checked ? document.getElementById('autocomplete').value : '');*/ 
 
    document.getElementById('route').value = ''; 
 
} 
 

 
// [START region_geolocation] 
 
// Bias the autocomplete object to the user's geographical location, 
 
// as supplied by the browser's 'navigator.geolocation' object. 
 
function geolocate() { 
 
    if (navigator.geolocation) { 
 
    navigator.geolocation.getCurrentPosition(function(position) { 
 
     var geolocation = new google.maps.LatLng(
 
     position.coords.latitude, position.coords.longitude); 
 
     var circle = new google.maps.Circle({ 
 
     center: geolocation, 
 
     radius: position.coords.accuracy 
 
     }); 
 
     autocomplete.setBounds(circle.getBounds()); 
 
    }); 
 
    } 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script> 
 
    <body onload="initialize()"> 
 
    <div id="locationField"> 
 
     <div class="clearfix"> 
 
    \t <label for="street_<cfoutput>#Add#</cfoutput>">Mailing Address 1:</label> 
 
    \t <input type="text" name="street_#Add#" validateat="onSubmit" validate="maxlength" required="yes" id="autocomplete" size="54" maxlength="120" message="Please enter owner #Peoplecount#'s mailing address." onFocus="geolocate()" value=""> 
 
    </div> 
 

 
    <div class="clearfix"> 
 
    \t <label for="m2street_<cfoutput>#Add#</cfoutput>">Mailing Address 2:</label> 
 
    \t <input type="text" name="m2street_#Add#" validateat="onSubmit" required="no" validate="maxlength" id="route" size="54" maxlength="120" value=""> 
 
    </div> 
 
     
 
    <div class="clearfix"> 
 
    \t <label for="city_<cfoutput>#Add#</cfoutput>">City:</label> 
 
    \t <input type="text" name="city_#Add#" validateat="onSubmit" validate="maxlength" required="yes" id="locality" size="30" maxlength="50" message="Please enter owner #Peoplecount#'s mailing city." value=""> 
 
     </div> 
 
     
 
     <div class="clearfix"> 
 
    \t <label for="state_<cfoutput>#Add#</cfoutput>">State:</label> 
 
    \t <input type="text" name="state_#Add#" required="yes" id="administrative_area_level_1" size="8" maxlength="12" message="Please enter owner #Peoplecount#'s mailing state." value=""> 
 
    </div> 
 
      
 
      <div class="clearfix"> 
 
    \t <label for="street_<cfoutput>#Add#</cfoutput>">Zip Code:</label> 
 
    \t <input type="text" name="postal_#Add#" required="yes" id="postal_code" size="8" maxlength="12" message="Please enter owner #Peoplecount#'s mailing zip code." value=""> 
 
    </div> 
 
     </div>

+0

Istnieje kilka technik uruchamiania javascript w programie Excel opisanych w tych odpowiedziach: http://stackoverflow.com/questions/20171885/excel-macros-with-javascript http://stackoverflow.com/questions/848246/how- can-i-use-javascript-in-an-excel-macro – Starscream1984

+0

czy mówisz, że to możliwe? Nigdzie nie mogę tego znaleźć. Udało mi się znaleźć sposób jego utworzenia, ale nie jak wykonać automatyczne wypełnianie adresu. –

+0

Wydaje się to teoretycznie możliwe, ale prawdopodobnie nie jest łatwe. Jestem bardzo ciekawy, dlaczego chcesz to zrobić w pierwszej kolejności? – Starscream1984

Odpowiedz

0

Czy to możliwe, aby korzystać z mojego skryptu jquery w arkuszu programu Excel? Próbuję użyć geolokalizacji, aby mieć funkcję automatycznego uzupełniania adresu.

Nie. Twój skrypt opiera się na interfejsie API Map Google, a to wymaga kontekstu przeglądarki do poprawnego działania.

Chociaż możesz uruchomić JavaScript w Hosta skryptów systemu Windows, potrzebujesz znacznie więcej niż JavaScript. Potrzebujesz API przeglądarki, wraz z API geolokalizacji i AJAX. Nie znajdziesz tego w Excelu.

Możesz jednak stać się twórczy. Możesz tworzyć żądania HTTP za pomocą skryptu (chociaż nie jest to normalny sposób AJAX). Prawdopodobnie możesz również uruchomić zewnętrzną aplikację, aby uzyskać dla ciebie pozycję.

Powiązane problemy