We’ve moved! You can see this post on the new site by clicking here.
XLSX.js is a library that converts base64 strings into object representations of XLSX spreadsheets, and vice versa. Now, some of you may be thinking, “I get the object representation of an XLSX spreadsheet part, I like that, but what good is a base64 string?” Well, actually, there are a lot of things you can do with base64 strings. Though sometimes a conversion from binary is required, you can obtain them from XHRs, FileReader, or Silverlight/Flash uploaders. And, similarly, you can send them to web services, FileWriter, Data URIs, or Sliverlight/Flash downloaders. In other words, this library will allow you to read and write Excel-compatible XLSX files when paired with an appropriate file access mechanism.
Current solutions for reading or writing XLSX data take one of two approaches; use ActiveX to communicate with Excel or send your data to a server for conversion. A number of the applications we had written required the ability to read and write Excel files, so we explored both options and found a number of concerns with each.
This may work in some situations, but there are a number of concerns with this method:
- One, ActiveX is only supported on Windows, using Internet Explorer. Still, even if that perfectly describes your audience, it looks as though ActiveX may be playing a diminished role in the future. Only the desktop version of Internet Explorer 10 supports ActiveX, it is not supported in the Modern UI, Windows Phone, or Xbox versions. Now, you may not need support for the Modern UI version or Windows Phone. And, I am sure there is no demand to generate XLSX files on the Xbox. However, I do think it is wise to pursue methods that are standards compliant and cross-browser compatible. Nobody knows what the future holds.
- Two, using the Excel ActiveX control requires that 100% of your audience has Excel installed. In some scenarios, that is not the case.
- Four, interacting with the ActiveX control is rather awkward. Most of the documentation and examples are for other programming languages, and it is not very efficient.
Our situations prevented the use of server-side code, so we were left with ActiveX. ActiveX, with the limitations described above, left us wanting more. Hence, we created XLSX.js!
OK, so, how does it work? Well, let’s start with a little information about XLSX files. As opposed to Excel’s previous format, XLSX is XML based. However, an XLSX file isn’t just one big XML document. It is a ZIP file composed of numerous XML files in a particular (folder) structure. Therefore, in order to interact with these XML files (either through string manipulation or DOMParser) we need to unzip the archive. XLSX.js leverages JSZip to unzip the file, and then it reads and correlates the data in the XML documents to generate an object representation of the XLSX file. For writing the file, it does all of that in reverse.
- JSZip: Yes, you will need JSZip in order for XLSX.js to work properly. XLSX.js does not come with, and will not be distributed with, JSZip. You will need to download the appropriate files, attach them to your project, and ensure you are in compliance with JSZip’s license by yourself.
- Features: Right now XLSX.js supports reading data from multiple worksheets, the names of the worksheets, the active worksheet, and file metadata. It does not support the reading of formatting information, macros, charts, or anything else. It also supports writing simple data to multiple worksheets, setting the names of the worksheets, setting the active worksheet, and setting file metadata. It also supports the ability to turn the data on a worksheet into a sortable table. It does not support the writing of formatting information, macros, charts, or anything else. However, this need not (and hopefully will not) be the case forever. Our situation did not require the development of any features beyond what you see listed above. As time goes on we may add features as we need them for other projects, or as we have free time. But, that doesn’t prevent the community from expanding and refining the feature set! Every feature should be possible, should you wish to add it.
- Support: No, we will not be providing official support at this time. We will try to answer your questions as we have time, and help as much as possible, but we are not currently in the position to guarantee any support, fixes, or updates.
- Demos & Documentation: Our first demo, located here, covers basic load functionality. Our second demo, located here, builds on these concepts to look at basic save functionality. For further demos and tutorials, please check back often!
- Word, PowerPoint, etc: Stay tuned…
- Licensing: XLSX.js has been released by Microsoft under the Microsoft Office Extensible File License. The text of this license can be found on GitHub, along with XLSX.js itself. The Microsoft Office Extensible File License is an open source license, but it is not OSI approved. This license has similarities to the MS-PL, but there are significant differences. Please read the Microsoft Office Extensible File License carefully before using XLSX.js
So, with that I give you XLSX.js! The source can be found on GitHub, located here: