How can I programmatically create, read, write an excel without having office installed?

How can I programmatically create, read, write an excel without having office installed?

I'm confused as hell with all the bazillion ways to read/write/create excel files. VSTO, OLEDB, etc, but they all seem to have the requirement that office must be installed.
Here is my situation: I need to develop an app which will take an excel file as input, do some calculations and create a new excel file which will basically be a modification of the first excel file. All with the constraint that the machine that runs this may not have office installed. (Don't ask why...)
I need to support all excel formats. The only saving grace is that the formats spreadsheets themselves are really simple. Just a bunch of columns and values, nothing fancy. And unfortunately no CSV as the end user might not even know what a CSV file is.


Solution 1:

write your excel in HTML table format:

    <td style="background-color:#acc3ff">Cell1</td>
    <td style="font-weight:bold">Cell2</td>

and give your file an xls extension. Excel will convert it automatically

Solution 2:

Without Office installed you’ll need something designed to understand the Excel binary file format (unless you only want to open Office 2007 .xlsx files).

The best I’ve found (and that I use) is SpreadsheetGear, which in addition to being .NET native, is much faster and more stable then the COM/OLE solutions (which I’ve used in the past)

Solution 3:

read and write csv files instead. Excel reads them just fine and they’re easier to use. If you need to work against .xls files then try having support for OpenOffice as well as Excel. OpenOffice can read and write excel files.

Solution 4:

Did you consider way number bazillion and one: using the Open XML SDK? You can retain styles and tweak it to your liking. Anything you can do in an actual file is possible to achieve programatically. The SDK comes with a tool called Document Reflector that shows the underlying XML and even shows LINQ statements that can be used to generate them. That is key to playing around with it, seeing how the changes are made, then recreating that in code.

The only caveat is this will work for the new XML based formats (*.xlsx) not the older versions. There’s a slight learning curve but more material is making its way on blogs and other sites.

Solution 5:

Excel XLSX files “just” XML files – more precisely ZIP files containing several XML files. Just rename a Excel file Test.xslx to and open it with your favourit ZIP program. XML schemas are, afaik, standardized and availiable. But I think it might not be that easy to manipulate them only using primitive XML processiing tools and frameworks.

Solution 6:

If cost is not an issue, I’d suggest looking in Aspose’s Excel product. I use their Word product and I’ve been satisfied.


Solution 7:

Excel files are in a proprietary format so (afaik) you’re not going to be able to do this without having the office interop available. Some third party tools exist (which presumably licence the format from MS?) but I’ve not used them myself to comment on their usefulness.

I assume that you can’t control the base file format, i.e. simple CSV or XML formats aren’t going to be possible?

Solution 8:

I used to use a very nice library called CarlosAg, which uses Excel XML format. It was great (and Excel recognizes the format), and also incredibly fast. Check it out here.

Oh, as a side note, we used to use this for the very same reason you need it. The servers that generated these files were not able to have Excel installed.

Solution 9:

If you cannot work with CSV files as per @RHicke‘s suggestion, and assuming you are working on a web app, since a desktop app would be guaranteed to have XL installed as per requirements.

I’d say, create your processing app as a webservice, and build an XL addin which will interact with your webservice directly from XL.

Solution 10:

For XLSX files, look at using Otherwise, some paid 3rd party solutions are out there, like the one David suggested.

Solution 11:

I can understand the requirement of not having office installed on a server machine.
There are many libraries like aspose being available, some of them requiring license though.
If you are targeting MS Excel formats, then a native, Interoperability library, ACE OLEDB data provider, from Microsoft is available which you can install on a machine and start reading, writing programmatically. You need to define a connection string and commands as per you needs. (Ref: This article @yoursandmyideas)talks about using this library along with setup and troubleshooting information.