Click here to Skip to main content
15,891,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working on a code and having some problems in it.
I am developing a code,which takes values from excel file as lattitude and longitude and place it on map as a marker.
The problem we are encountering is that only first two cells(means lattitude and longitude for one marker) are plotted.
I need to place several markers at the positios mentioned in the excel sheet.
The code is attached here.
HTML
<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&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q" type="text/javascript"></script>  
    <script type="text/javascript">
</script></head></html>

JavaScript
function my_function()
{    
   var Excel; 
   Excel = new ActiveXObject("Excel.Application"); 
   Excel.Visible = false; 
   return Excel.Workbooks.Open("C:/desktop/TEST.xls").ActiveSheet.Cells(l,i).Value;}
//where l is number of rows and i are columns...
var i=1;
var l=1;
do
{  
  a = my_function()   
  if (a!=null)  
  {    
    i++; 
     b=my_function()
     if(b!=null)
        initialize()
     i++;
  }   
  else
  {       
     l++;       
     i=1;        
  }    
}
while(a!=null || b!=null);
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(24.884801, 67.056469), 13);
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());
   
    var point = new GLatLng(a , b);
    map.addOverlay(new GMarker(point)); 
  }
}

HTML
  <body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;"> 
    <h1 align="center">Plotting</h1> 
<hr width="50%"> 
    <div id="map_canvas" style="width: 900px; height: 1000px"></div> 
  </hr></body> 

PS I guess there is some problem with do-while loop.
Please help me out.
Confused geminien
Posted
Updated 29-Jun-10 17:29pm
v6

1 solution

You're opening up the Excel file at each loop. That's probably being locked from the first instance it is called and not reading it in the loop. Move your Excel.Workbooks.Open code into the initialize function and pass it to your function as a parameter. Since this is Excel, you can also make it a global variable.
 
Share this answer
 

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