I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference. My dev computer has Excel on it, but the end user may or may not have Office installed. Will this tool fail if Office isn't installed on the end users computer, or is this interop service separate from the actual application?
-
I've published a free-to-use C# library to do this: http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm – Mike Gledhill Dec 04 '13 at 15:33
-
Gledhill that link doesn't work. Nevertheless, I found [GemBox.Spreadsheet](https://www.gemboxsoftware.com/spreadsheet) that can create any Excel file (XLS, XLSX, ODS, CSV, etc.) without MS Office, and it has a free version that can be used anywhere. – hertzogth Feb 11 '20 at 09:14
7 Answers
If you're interested in making .xlsx (Office 2007 and beyond) files, you're in luck. Office 2007+ uses OpenXML which for lack of a more apt description is XML files inside of a zip named .xlsx
Take an excel file (2007+) and rename it to .zip, you can open it up and take a look. If you're using .NET 3.5 you can use the System.IO.Packaging library to manipulate the relationships & zipfile itself, and linq to xml to play with the xml (or just DOM if you're more comfortable).
Otherwise id reccomend DotNetZip, a powerfull library for manipulation of zipfiles.
OpenXMLDeveloper has lots of resources about OpenXML and you can find more there.
If you want .xls (2003 and below) you're going to have to look into 3rd party libraries or perhaps learn the file format yourself to achieve this without excel installed.

- 54,668
- 9
- 68
- 101
-
1OpenXMLDeveloper shut down sometime in 2018. Per the page, much of the content was moved to [EricWhite.com](http://www.ericwhite.com/blog/) – CarenRose Dec 19 '18 at 19:39
Unless you have Excel installed on the Server/PC or use an external tool (which is possible without using Excel Interop, see Create Excel (.XLS and .XLSX) file from C#), it will fail. Using the interop requires Excel to be installed.

- 1
- 1

- 162,879
- 31
- 289
- 284
Try EPPlus if you use Excel 2007. Supports ranges, cellstyling, charts, shapes, pictures and a lot of other stuff

- 401
- 1
- 5
- 4
-
Also works with newer versions of Excel, don't be put off by the "2007". Available on NuGet. Newer link to documentation here: https://github.com/JanKallman/EPPlus/wiki/Getting-Started – Savage May 31 '19 at 12:11
-
There are a handful of options:
- NPOI - Which is free and open source.
- Aspose - Is definitely not free but robust.
- Spreadsheet ML - Basically XML for creating spreadsheets.
Using the Interop will require that the Excel be installed on the machine from which it is running. In a server side solution, this will be awful. Instead, you should use a tool like the ones above that lets you build an Excel file without Excel being installed.
If the user does not have Excel but has a tool that will read Excel (like Open Office), then obviously they will be able to open it. Microsoft has a free Excel viewer available for those users that do not have Excel.
-
+1 for Aspose. I've used it to great success, and it is very easy to work with. – rmeador Apr 16 '10 at 18:14
-
NPOI has worked well for my purposes (e.g. no budget to buy anything). However, it does not support .xslx generation. – Odrade Apr 16 '10 at 19:25
-
1@rmeador Well you certainly are lucky. I've had nothing but grief using Aspose. Horrible quality control with numerous undocumented changes, constant silly bugs, questionable api design (NullReferenceException when setting a property to null.. wtf?!) Their only saving grace is fixes come out at a decent rate, but every fix they release means wasted hours spent testing their patches since it's impossible to trust what they give you. – Krypes Apr 16 '10 at 19:39
-
@Odrade - Xslx was not mentioned as part of the specification and is not universally readable. However, if xslx is what you want to do, then you can use the Open Office XML format. – Thomas Apr 16 '10 at 19:41
-
1@Kyrpes - I'm not sure when you last used Aspose.Cells, but it is used in the project on which I'm working for a few years and beyond the high cost, it has worked flawlessly. We've never had one issue with it. – Thomas Apr 16 '10 at 19:44
-
Hate to disagree but NPOI is quite limited. Using ooxml might be harder/more code but it does everything and with the autogenerating code from the sdk it's a better technique at least for templates as well as workbooks that are easily dissected – Anonymous Type Mar 15 '11 at 08:17
-
@Anonymous Type - Unfortunately, OOXML will not make Excel 97-2003 binary files and NPOI will. I agree that OOXML has more features but the one limitation of not making a true binary Excel file is often a deal breaker. – Thomas Mar 15 '11 at 15:54
-
@Thomas, I'm not sure, perhaps you misread the question. the OP says "the end user may or may not have Office installed" this seems to be a more important requirement than the file format. If the user hasn't got Excel or only <=2003 they can still open the ooxml file. I agree NPOI has a place in environments that require the 2003 file format. – Anonymous Type Mar 16 '11 at 11:04
-
@Anonymous Type - The OP also suggests that the user may have Excel so the result needs to be compatible with those versions (although we are not told the minimum version supported). I've also found the Excel viewers to be persnickety when it comes to opening OOXML or Speadsheet ML files. – Thomas Mar 16 '11 at 16:37
-
An interop calls something else, it's an interoperability assembly, so you're inter-operating with something...in this case Excel, the actual installed Excel.
In this case yes, it will fail to run because it depends on excel, you're just calling excel functions. If they don't have it installed...out of luck.
There are methods to generate without Excel, provided the 2007 file format is ok, here's a few:
as I said though, this is the 2007 format, normally if anything, that's the deal-breaker.

- 623,446
- 136
- 1,297
- 1,155
-
1+1 for pointing out that the "interop" needs something to interoperate with. – John M Gant Apr 16 '10 at 18:53
Use OleDB, you can create, read, and edit excel files pretty easily. Read the MSDN docs for more info:
http://msdn.microsoft.com/en-us/library/aa288452(VS.71).aspx
I've used OleDB to read from excel files and I know you can create them, but I haven't done it firsthand.

- 4,002
- 2
- 19
- 21
You could use the ExcelStorage Class of the FileHelpers library, it's very easy and simple... you will need Excel 2000 or later installed on the machine.
The FileHelpers is a free and easy to use .NET library to import/export data from fixed length or delimited records in files, strings or streams.

- 11,878
- 8
- 54
- 108