5

I am using Microsoft Excel Interop library for exporting Excel file. However, the limit of this library is that:

  • Require the user's computer must have Microsoft Excel.
  • When write the content, Microsoft Excel must be opened to automate.
  • To save file, user must do manually: click on File -> Save.

I need a library:

  • Write the content to memory with Excel format.
  • Save this content to file programmatically.

Notes: I use .net 2.0 and C#.

Thanks.

Leo Vo
  • 9,980
  • 9
  • 56
  • 78

3 Answers3

10

I have used EPPlus for .xlsx reading/writing and it has worked great

BrandonAGr
  • 5,827
  • 5
  • 47
  • 72
  • 2
    +1 I've used it also. Writing excel spreadsheets > 65k rows was a breeze. – PostMan Mar 22 '11 at 02:43
  • 1
    .xlsx is compatibled with Excel 2003? I need a Excel format which can be opened with Microsoft Excel 2003. Thanks. – Leo Vo Mar 22 '11 at 04:05
  • Excel 2003 can open .xlsx files if you install the Microsoft compatibility pack : http://office.microsoft.com/en-us/support/microsoft-office-compatibility-pack-for-word-excel-and-powerpoint-2007-file-formats-HA010168676.aspx – Joel Gauvreau Mar 22 '11 at 12:37
1

I think the only way to achieve this without having Excel installed is to just write the file format directly. Microsoft documented the file format a few years ago. You can find them at http://msdn.microsoft.com/en-us/library/cc313118.aspx.

Update I've just found EPPlus. Check it out at http://epplus.codeplex.com/

Andrew Cooper
  • 32,176
  • 5
  • 81
  • 116
1

You can use an ODBC or OLE connector to read and write an Excel file. However, I am not sure if you can create a file with it, you might need to keep a dummy-empty file with the correct layout.

Update: It is, accordingly to comment below from @Joel Gauvreau possible to create an excel file using this technique.

Links: http://support.microsoft.com/kb/257819

http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c1131

stefan
  • 2,886
  • 21
  • 27
  • 2
    It is what I'm doing, and you can create an empty file with the correct layout, dump the raw data in a worksheet. You can create some nice looking worksheet that link to this data if you need. It works well. The file does not need to exist, you must however create the schema first if you are not using an existing file. – Joel Gauvreau Mar 22 '11 at 03:02
  • @Joel thank you, I wasn't sure if it was possible. I will add a note of your response in the answer. – stefan Mar 22 '11 at 03:04
  • 2
    The result is much nicer with an existing file that you can format before hand. By creating the file with the OleDbConnection you just get a plain list of the data. – Joel Gauvreau Mar 22 '11 at 03:15
  • This answer pretty much sums it up : http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c/151048#151048 – Joel Gauvreau Mar 22 '11 at 03:23