Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript Excel
hi
i was trying to read an excel file in JavaScript, using 'for' and 'do-while' loop.
 
My requirement is to read an excel file and show values in web browser using Javascript, until "null" appears.
I want my program to read values row by row.
I have designed a code but it is reading only one cell of excel.
function my_function()
{
   var Excel;
	Excel = new ActiveXObject("Excel.Application");	
	Excel.Visible = false;
	a=Excel.Workbooks.Open("C:/desktop/TEST.xls").ActiveSheet.Cells(l,i).Value;
	//Excel.Quit()
	return a;
}		
 
//where l is number of rows and i are columns...
var i=1;
var l=1;
do
{
a=my_function()
document.write("value is " +a+"\t");i++;
if (a=="");
{l++;
i=1;
document.write("\n");
}
}
while(a=="");
when i specified the number of rows and columns in same program,it worked.
 
Please help me why it is not working?
Posted 3-Jun-10 20:18pm
hadi n332
Edited 3-Jun-10 20:25pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are lot of logical as well as syntax errors in the code you have provided. I have tried to correct those with minimum changes to your original code.
 
The below code should work,
 
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)
    {
        document.write("value is " + a + "&nbsp ;&nbsp ;&nbsp ;&nbsp ;");
        i++;
    }
    else
    {
        l++;
        i=1;
        document.write("<br />");
    }
 
    b = my_function()
}while(a!=null || b!=null);
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,696
1 Sergey Alexandrovich Kryukov 6,675
2 CPallini 5,315
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 4 Jun 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100