Click here to Skip to main content
15,914,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I've a problem that when i'm loading program of reading the excel sheet using "usedrange" property so its running well but when i integrated this code with my Google map API code so its showing an error in property of "usedrange" is that "its undefined or null or not an object".

Please can anyone make this code run well.Or tell me the better alternative. I'm badly in need of this code error free:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
<title>Google Maps API Sample</title> 
<script src="http://maps.google.com/maps?file=api&v=2&sensor=fa lse&key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8m ADN a0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q" type="text/javascript"></script>  
</head> 
<body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;">
<div id="map_canvas" style="width: 500px; height: 300px"></div> 
</body> 
</html>


JavaScript
function initialize() { 
var farah=new Array() 
var Excel; 
Excel = new ActiveXObject("Excel.Application") 
Excel.Visible = false 
var a=Excel.Workbooks.Open("C:/desktop/test.xlsx").sheets(1) 
for (var r=1;r<=a.usedrange.rows.count;r++) 
{farah[r-1]=new Array() 
for (var c=1;c<=a.usedrange.columns.count;c++) 
farah[r-1][c-1]=a.Cells(r,c).Value;} 
var x=0,y=0; 
for(len in farah) 
{x+=farah[len][1]; 
y+=farah[len][2];} 
p1=(x/farah.length) 
p2=(y/farah.length); 
//document.write(p1+p2); 
if (GBrowserIsCompatible()) 
{ 
var map = new GMap2(document.getElementById("map_canvas")); 
var center = new GLatLng(p1,p2); 
map.setCenter(center, 10); 
map.addControl(new GSmallMapControl()); 
map.addControl(new GMapTypeControl()); 
function createMarker(point) { 
var marker = new GMarker(point); 
GEvent.addListener(marker, "click", function() { 
marker.openInfoWindowHtml("Marker lattitude and longitude" + point + "karachi" ); 
}); 
return marker; 
} 
var point=new GLatLng(78.9,122.9) 
map.addOverlay(createMarker(point)) 
}} 
Posted
Updated 18-Jun-10 7:26am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900