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?

5 Answers 5

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

Sign up to request clarification or add additional context in comments.

4 Comments

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...)
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.
@wybiral niggler.github.io/js-xlsx and niggler.github.io/js-xls appear to fit the bill
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.......
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

Comments

-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.

Comments

-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.

Comments

-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.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.