在Excel Spreadsheets中运行JQuery Geolocation脚本

是否有可能在Excel电子表格中使用我的jQuery脚本? 我正在尝试使用地理定位function的自动地址填写。我有能力做到这一点通过HTML。 但是我很好奇我如何才能在Excel工作表中实现相同的目标。

我想要在电子表格中的列是地址,城市,州,邮编,然后每次地址被点击进入我希望它预填充和给我这样的HTML版本的build议。

请有人协助,这可能是可能的。

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"> <label for="street_<cfoutput>#Add#</cfoutput>">Mailing Address 1:</label> <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"> <label for="m2street_<cfoutput>#Add#</cfoutput>">Mailing Address 2:</label> <input type="text" name="m2street_#Add#" validateat="onSubmit" required="no" validate="maxlength" id="route" size="54" maxlength="120" value=""> </div> <div class="clearfix"> <label for="city_<cfoutput>#Add#</cfoutput>">City:</label> <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"> <label for="state_<cfoutput>#Add#</cfoutput>">State:</label> <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"> <label for="street_<cfoutput>#Add#</cfoutput>">Zip Code:</label> <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> 

是否有可能在Excel电子表格中使用我的jQuery脚本? 我正在尝试使用地理定位function来自动填写地址。

不可以。您的脚本依赖于Google Maps API,这将需要浏览器上下文才能正常工作。

虽然您可以在Windows Script Host中运行JavaScript,但您所需要的远不止JavaScript。 您需要一个浏览器API,包含地理定位API和AJAX。 你不会在Excel中find。

但是,您可以获得创意。 你可以用脚本发出HTTP请求(虽然不是正常的AJAX方式)。 你也可以执行一个外部应用程序来获得你的位置。