Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Excel data with JQuery

I would like to know how to read data from a multi-worksheet MS Excel 2003 file using nothing, but jquery. I have read several solutions for PHP/JQuery, ActiveX, etc..., but I would like to do it with JQuery ONLY. Any idea of how this could work?

I have found http://plugins.jquery.com/project/csv2table and this does the job almost perfectly, except for the fact that I have to break each sheet out into a CSV file. I would like to drop that step and read it directly from the Excel file. Thank you in advance for your help!

BTW - I am working in FireFox 4 and have no need for cross browser support.

like image 800
Robert Fleming Avatar asked Mar 31 '11 01:03

Robert Fleming


People also ask

How read data from Excel using jQuery?

First, we will create a File Upload button, then an HTML table which is hidden first, and lastly ab Input button which upon clicking, calls the function to export Excel data to the HTML table. Running the page will look like below. Now, we reference the jQuery plugin files "xlsx.

How fetch data from Excel in Javascript?

Javascript Excel - Import Data From ExcelThe Excel file is read into Uint8Array object, which is then passed to the load method exposed by the Excel library. Once the worksheet is loaded into the Excel library object, we can read each cell value and build a JSON array that will be used as the igGrid data source.


2 Answers

Office Web Components provide an api to excel documents via javascript (or vb). They are poorly documented but for intranet type applications they can get the job done. I have used them for the pivot table functionality in IE6 and do not know if it will work with Firefox.

http://en.wikipedia.org/wiki/Office_Web_Components

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=beb5d477-2100-4586-a13c-50e56f101720&DisplayLang=en

like image 165
jason saldo Avatar answered Sep 23 '22 05:09

jason saldo


Actually it's possible without OWC and such exotic addins, but manual work will be required. Another thing - it's doable on local machine only - don't expect your worksheet to act like a web server. Another possibility is to set it up on a network share, but I'm not sure how will it all work in the sandbox.

EDIT: I know the question was about Excel 2003 format. However, there are still Google queries about the same functionality and today people are using MS Office versions 2010/2013. So, I believe the answer can be beneficial to the reader.

So, here it is:

  1. Using zip.js you can open zipped files. This means you can open MS Office files starting from Office 2007 (.docx, .xlsx. etc). Older office files have custom format and you can't read them as zipped files.
  2. After you open the file, hierarchical folder structure with various files in it is available. The data itself is in /xl/worksheets/[worksheet name].xml and /xl/sharedStrings.xml, which means you have to dig it out using XML parser and correlate afterwards.
  3. Luckily enough, XML parser is available in jQuery: $.parseXML('...')

Have fun ;)

like image 23
OzrenTkalcecKrznaric Avatar answered Sep 22 '22 05:09

OzrenTkalcecKrznaric