7

I am trying to write a small web tool which takes an Excel file, parses the contents and then compares the data with another dataset. Can this be easily done in JavaScript? Is there a JavaScript library which does this?

SheetJS
  • 22,470
  • 12
  • 65
  • 75
vivekian2
  • 3,795
  • 9
  • 35
  • 41

5 Answers5

6

How would you load a file into JavaScript in the first place?

In addition, Excel is a proprietary format and complex enough that server side libraries with years in development (such as Apache POI) haven't yet managed to correctly 100% reverse engineer these Microsoft formats.

So I think that the answer is that you can't.

Update: That is in pure JavaScript.

Update 2: It is now possible to load files in JavaScript: https://developer.mozilla.org/en-US/docs/DOM/FileReader

cherouvim
  • 31,725
  • 15
  • 104
  • 153
  • JavaScript can't read a file in itself (except for somewhat recent additions that probably are not available in IE), but you can help it with that using a webserver that responds to an AJAX-request with the filecontents. Managing arbitrary binary data is not easy either in JS (Except for recent additions, probably not IE-compatible yet...) – Frank Jan 21 '11 at 17:31
  • 3
    I'm not sure what the state of the art was at the time of this post, but now we do have APIs like the FileReader object in Firefox, Opera, and Chrome for loading files into Javascript.The proprietary nature of the format is still an issue, though I have seen libraries for other languages capable of parsing basic Excel files, just not in Javascript. –  Nov 26 '12 at 04:02
  • @wybiral http://niggler.github.io/js-xlsx/ and http://niggler.github.io/js-xls/ appear to fit the bill – Soul Ec Oct 16 '13 at 04:19
  • Absolutly right user can make some kind of xml data parse it to javascript and then bind it or can do some client side work from that one but that's not possible to do it at client side....... – Just code Oct 16 '13 at 04:19
2

In the past four years, there have been many advancements. HTML5 File API has been embraced by the major browser vendors and performance enhancements actually make it somewhat possible to parse excel files (both xls and xlsx) in the browser.

My entries in this space:

Both are pure-JS parsers

SheetJS
  • 22,470
  • 12
  • 65
  • 75
-1

You will need to use ActiveX (see W3C Schools on the use of AJAX) and register the file in the hosting computers Dataconnectors (only the computer hosting the file). Unlike mentioned before, this method is not Microsoft platform dependant (for the client anyways) and you do not need to have Office components installed.

This can be done for most datafiles registered in Windows, including MDB's, and allows you as much control as you want, as you can assign different Windows Accounts for different purposes.

Like I said before, this all is serverside and has no impact on the client, apart from maybe retrieving credentials, actions and all that.

This method uses JavaScript, SQL (no, not even MSSQL, just SQL standard) and requires only that the hosting computer is running ANY Microsoft NT platform.

What Windows dataconnectors do is provide a generalised interface for various data components much like DirectX does for videocards and other peripherals. You can also use it to link an MDB (Microsoft Access) to a MySQL server and feed data live that way, which I believe is even simpler than using XLS spreadsheets...especially since you can import XLS into MDB.

RolanDecoy
  • 37
  • 3
-1

To do everything in js, you'll have to use ActiveX and probably the office web components as well. Just a suggestion, but you probably don't want to go this route; it'll be inefficient and IE/Win only. You'll be better off with a server based solution.

Jerod Venema
  • 44,124
  • 5
  • 66
  • 109
-2

Do you really need an Excel file? Why not use Excel to export the data in CSV or XML and load that?

The Excel file format is very specific to Excel's implementation. If you just need the data, use a file format that just contains the data.

Matthew Marshall
  • 5,793
  • 2
  • 21
  • 14
  • 1
    The problem with that solution is it requires manual intervention. The excel has multiple worksheets with a lot of fomulas and there is no easy automated way to convert xls to csv, atleast of which i know. Please do update this if you know of some tool which does this in a simple way. – vivekian2 Mar 11 '09 at 17:10