How to read excel cell values using javascript [closed]

So, I need to be able to read an Excel sheet and access the values of cells. So far I have just created a small demo in an attempt to test code that I have seen elsewhere, but so far I’ve had no luck. Here’s the demo: function readFile() var excel=new ActiveXObject(“Excel.Application”); var excel_file = …

via Word Tutorials » Search Results » ajax:

How to read excel cell values using javascript [closed]

So, I need to be able to read an Excel sheet and access the values of cells. So far I have just created a small demo in an attempt to test code that I have seen elsewhere, but so far I’ve had no luck. Here’s the demo:
function readFile()
var excel=new ActiveXObject(“Excel.Application”);
var excel_file = excel.Workbooks.Open(“C:\temp\mod9.csv”);
var excel_sheet = excel_file.Worksheets(“mod9″);
var data = excel_sheet.Cells(1,1).Value;
alert(data);
return data
Really, with this demo I was just trying to see if I could pull a single value, but whenever I try to run this, it stops at the very first line of the function. It says “ActiveXObject is not defined.” If you have another suggested way to read the file, then I would be happy to read that as well. Any help would be appreciated.
……………………………………

As the comments to your question say, it’s not recommended to use the ActiveXObject in javascript since it will only work in IE, if you want to have a cross browser solution you’ll have to take another approach. More than that, as @SimonWang commented, not only will the user need to open the page with IE he will also need to have Excel installed on his machine, otherwise it won’t work.
You can read the excel file on the server side, parse the data and return it to the javascript side with let’s say an ajax request. I’m not sure how your server side is implemented, but there are solutions for that with almost every language out there. For example with php, you can check out this: http://php.net/manual/en/function.fgetcsv.php
……………………………………

If you would like the excel spreadsheet so that any user can see it, you can publish it as a webpage using Google Docs.
Instructions are provided here:
http://support.google.com/docs/bin/answer.py?hl=en&answer=55244
Let me know if this helps.
EDIT
Sorry I think I got confused by your question.
Have you thought about using excel functionality to export the worksheet as CSV or XML and searching the files that way.
File -> Save As -> Excel Workbook, CSV, XML, Web Page (HTML) ….

For more info: How to read excel cell values using javascript [closed]

Word Tutorials » Search Results » ajax

How to read excel cell values using javascript [closed]

Share this post:

Related Posts

Leave a Comment