I need to create and populate excel file in c#. With Microsoft.Office.Interop.Excel , it can be created easily but it need to install Office on server. I am looking for solution without Office installation and without any third party components.
- 1Does the file have to be an Excel file or just readable by Excel? If it's the latter then you could just write an xml file or csv file.– ChrisF♦CommentedMar 2, 2011 at 15:47
- I'd just use Aspose.Cells. Your requirement that there should be no third party components seems rather constraining.– David HeffernanCommentedMar 2, 2011 at 16:06
3 Answers
It depends, if you just need to create an export that your user need to be able to open with Excel, then you might think of creating a CSV export.
Otherwise you may consider NPOI. I know it's a third-party lib, but it's open source :)
At my previous company, we created a "template" excel workbook (docx) and used the System.IO.Packaging
classes to open it in code, and replace the contents of the cells.
This also had the advantage of allowing us to style the spreadsheet up in Excel (in the template) to give a much prettier report!
You could just use the OpenOffice API, which is free. It will have basically the same functionality as Office and the spreadsheets created with it are compatible with Excel. OpenOffice API Wiki