Using NExcel To Avoid MS-Office Dependencies
October 21, 2010 Leave a comment
I recently was writing a utility application to was required to read data from an Excel spreadsheet and write it to both XML documents and plain text files. The catch was that this had to be done on machines on which it was not guaranteed that Microsoft Office would be installed.
I was creating the utility using C# and the .NET Framework. The writing to XML and text files was easy enough; the .NET Framework provides several ways to accomplish that. But what about reading from Excel? I went looking, and found NExcel.
NExcel (http://nexcel.sourceforge.net/) is an open-source port of JExcelAPI (an open source Excel API for Java) written entirely in C# that does not require the presence of MS Office Excel or any other 3rd party libraries.
NExcel does have its limitations. For one, it reads Excel 97, 2000, XP, and 2003 documents, but not Excel 2007 (or presumably 2010) documents. Also, it only supports reading of spreadsheets, not writing. A lesser limitation is that it cannot read spreadsheets with images.
Unfortunately, it appears that further development of the tool has died, as the latest released version is more than five years old. So I expect that the limitations of the released API will not be removed. However, the source code for the API is available, so anyone with the need/interest/ability can modify the API to suit their needs.
Despite the limitations, NExcel is good at what it does. And, the fact that it eliminates dependencies on Office can be a tremendous benefit, particularly for server-based applications or situations in which the presence of Office cannot be assured.
Following is a short example of using NExcel to read data from a spreadsheet. In this example, the location of data within the spreadsheet is known in advance, so it is possible to simply read from specific cells.