17

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.

SheetJS
  • 22,470
  • 12
  • 65
  • 75
Robert Fleming
  • 294
  • 1
  • 2
  • 8
  • This may be helpful: http://msdn.microsoft.com/en-us/library/cc313154.aspx – icktoofay Mar 31 '11 at 01:33
  • 25
    This is kind of insane – Michael Haren Mar 31 '11 at 01:35
  • 3
    The format of Excel 2003 files is *very* complicated. How much time are you willing to dedicate to completing this project? It'll take a while.. – thirtydot Mar 31 '11 at 01:40
  • 2
    I don't think you are going to find a jquery solution, but most likely you can find a microsoft API for javascript. – Rocky Pulley Aug 17 '12 at 20:16
  • I'm fairly sure it's at least somewhat possible to use JScript to automate Excel, and http://support.microsoft.com/kb/234774 seems to imply that it can be done from within the browser. I suspect it may require IE, though. – Matthew Daly Aug 17 '12 at 20:22
  • Would it be helpful to turn the excel file into a CSV and then find a CSV to JSON converter, and then read the JSON with Jquery? Example: http://stackoverflow.com/questions/662859/converting-csv-xls-to-json – theJerm Sep 25 '12 at 20:36
  • 3
    I can't believe this question was upvoted this many. Jquery is a javascript library mainly for easy html query. And OP wants reading binary Excel file with that library. Reading from where? Without ajax, there is no functionality in javascript to read file from server. So it must be a local file it should read. With javascript, it will take a long to read such an Excel file. But what do we gain from reading the file with jquery? This sounds like a bad design to me. – Tae-Sung Shin Oct 20 '12 at 20:13
  • Decoding xlsx files from recent versions of excel would be easy, but excel 2003 uses biff8 encoded files, so you'd have to write a decoder. Here's one in ruby that's well documented: https://github.com/alexmchale/ruby-spreadsheet/blob/master/lib/spreadsheet/excel/reader.rb – zaius Oct 24 '12 at 02:01
  • @zaius that project hasn't been updated in years ... – SheetJS Jun 08 '13 at 16:03
  • Sure, but the format has changed in years either :P – zaius Jun 09 '13 at 23:38
  • @zaius at a high level they haven't (same biff record structure) but there are a slew of new records introduced in 2010/2013. The password-protected xlsx files, for example, are actually the old-style xls files (i don't know why they didn't decide to just use zip passwords). It's a mess – SheetJS Jun 10 '13 at 13:42
  • @zaius that link 404s now (and the entire project appears to have been removed). – SheetJS Oct 19 '13 at 21:20

5 Answers5

8

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

jason saldo
  • 9,804
  • 5
  • 34
  • 41
4

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 ;)

OzrenTkalcecKrznaric
  • 5,535
  • 4
  • 34
  • 57
  • -1: that only applies to xlsx. excel 2003 uses the old binary format – SheetJS Jun 08 '13 at 15:59
  • 1
    @Nirk - I know, you can read that from my answer ('...you can open MS Office files starting from Office 2007...') – OzrenTkalcecKrznaric Jun 10 '13 at 09:45
  • Your response is analogous to confusing java with javascript. the question was written in 2011, after office 2007 and office 2010 were released, which means "Excel 2003" specifically refers to files generated from that version. Excel 2003 iirc couldn't generate OOXML – SheetJS Jun 10 '13 at 13:30
3

I realize this question is old, but I have a basic parser that supports most of what you are asking for: http://oss.sheetjs.com/js-xls/

SheetJS
  • 22,470
  • 12
  • 65
  • 75
  • Big up for making the plugin - is there any way that it can work without installing a huge plugin on a server, or does it require a server? – Jakob Oct 11 '14 at 11:02
  • 1
    @Jakob The web link runs entirely in the web browser (no server required, no data uploaded -- try it out and check the network traffic). It can also be used in nodejs on the server side. – SheetJS Oct 13 '14 at 02:56
0

There are a few tools (libraries) for nodeJS that you can find on the npm website. There's one called excel that reads xlsx files and there's one called office for most ms office files. Now since it's all Javascript anyway, you should be able to download, and check out the source to find a way to integrate it on the client-side. Hope that helps

Naman Goel
  • 1,525
  • 11
  • 16
-2

Convert the excel in a CSV file to get read from Jquery. make use of the Jquery plugin CSV2Table

<div id="view1"></div>
<script type="text/javascript">
$(function(){
    $('#view1').csv2table('Path/Anil.csv');
});
</script>
Gaurav Agrawal
  • 4,355
  • 10
  • 42
  • 61