Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Javascript Javascriptexamples JavaScript get excel file data

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript get excel file data

Advertisement
This page discusses - JavaScript get excel file data

JavaScript get excel file data

        

By the use of JavaScript we can get the excel file data as well. Here is the example which gets the data from the excel file with the cell and row index values.

To explain this we have created a simple HTML page into which we have four buttons which calls the method GetData(cell,row) as defined in the JavaScript.

 function GetData(cell,row){
  var excel = new ActiveXObject("Excel.Application");
  var excel_file = excel.Workbooks.Open("C:\\amitdata.xls");
  var excel_sheet = excel.Worksheets("Sheet1");
  var data = excel_sheet.Cells(cell,row).Value;
  document.getElementById('div1').innerText =data;
   }

First line of the function creates a new reference object of ActiveXObject for excel application. In the second line we have located the excel file and third line describes which sheet's data we are going to use. Now we can get the data at the specific cell and row position from this sheet. It works with Internet Explorer browser.

Excel file data is as  :

Here is the full example code as follows :

 <html>
<head>
<title>
Style Get data from excel sheet
</title>
<script language="javascript" >
  function GetData(cell,row){
  var excel = new ActiveXObject("Excel.Application");
  var excel_file = excel.Workbooks.Open("C:\\amitdata.xls");
  var excel_sheet = excel.Worksheets("Sheet1");
  var data = excel_sheet.Cells(cell,row).Value;
  document.getElementById('div1').innerText =data;
  }
  </script>
</head>
<body>
<p>&nbsp;</p>
<div style="background: #009955; width:'100%';" align="center">
  <font color="#000080" size="12pt">
<b>Get data from excel sheets</b>
  </font>
</div>
<center>
<p>&nbsp;</p>
<div id="div1" style="background: #DFDFFF; width:'100%';" align="center">
Click buttons to fetch data from c:\amitdata.xls
</div>
<input type="button" value="cell(1),row(1)" onClick="GetData(1,1);" />
<input type="button" value="cell(1),row(2)" onClick="GetData(1,2);" />
<input type="button" value="cell(2),row(1)" onClick="GetData(2,1);" />
<input type="button" value="cell(2),row(2)" onClick="GetData(2,2);" />
</center>
</body>
</html>

Output :

Click on the button "cell(1), row(1)"

Click on "Yes". It will show you the cell(1), row(1) value i.e "amit".

Click on next button to fetch data from the cell(1) and row(2)

Above image shows fetched data from cell(1) and row(2). Click on next button to fetch data from the cell(2) and row(1)

Above image shows fetched data from cell(2) and row(1). Click on next button to fetch data from the cell(2) and row(2)

Above image shows fetched data from cell(2) and row(2).

Download Source Code

        

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: JavaScript get excel file data  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:16
Gabby
July 15, 2012
Re Data from excel sheets

I have copied your code and changed the location of the excel sheet from which the data is to be fetched but when I click the cells nothing happens please help this is the exact code am looking for so my users can put in a password which will in turn call and display their outstanding balance from a cell in my spreadsheet
Safan Abdul
August 24, 2012
data Fetch

Hi, Im very new to Javascript and was hoping someone could help me run a program that fetches the inventory list from a website. I downloaded the scraper from here: http://sourceforge.net/projects/walmartscraper/ I am an idiot when it comes to JavaScript, and have no idea what I'm doing. PLEASE HELP!!!
Chris
September 28, 2012
Can you pass cell data to a variable?

Can you pass cell data to a variable?
Guilherme
October 18, 2012
submit file

Hi, I understand your example, but i would like of read xls data by file uploaded. How I can do this? thanks bye
oliver
November 13, 2012
write to excel

any way to use this process in reverse? ie, take a piece of data and write it to an existing excel file?
Pedro Manuel
March 26, 2013
Congrats

Congrats... I've been solving an issue, and this post saved me. Thanks a lot. Pedro Maths
Ahmad Radi
May 2, 2013
Thanks man

Thanks alot!!!
Vishal
January 10, 2014
Excel

i need to display excel sheet row data according to the row id entered in the user input box on html page please help.
ZecaPOA
July 17, 2012
Really good job.

To be perfect I need to know how do I make show 'div1' like a tooltip when the mouse over any button.
DMCA.com