This project has moved. For the latest updates, please go here.

Save in XLS ? (Excel 2003)

Apr 11, 2011 at 8:41 AM

Hi,

Is it possible to save in XLS?

Thank you for your advice.

Coordinator
Apr 11, 2011 at 10:19 AM

No, only XLSX, but you can open it in Excel 2003 if you have the compatibility pack installed.

If you need XLS, have a look at the NPOI project here on Codeplex.

Jan

Apr 11, 2011 at 12:44 PM
Edited Apr 11, 2011 at 12:44 PM

ok, thank's but I desperately search program that can read and write both formats : XLS & XLSX...

Apr 11, 2011 at 3:40 PM
Edited Apr 11, 2011 at 3:42 PM

You can save to XLS: example code that I'm using:

ExcelPackage pck = new ExcelPackage();
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
ws.Cells["A1"].LoadFromDataTable(dataTable, true);
FileStream aFile = new FileStream("c:\\data\\excelfile.xls", FileMode.Create);
byte[] byData = pck.GetAsByteArray();
aFile.Seek(0, SeekOrigin.Begin);
aFile.Write(byData, 0, byData.Length);
aFile.Close();
Jun 27, 2012 at 3:14 PM
Edited Jun 27, 2012 at 3:14 PM
jtpatil wrote:

You can save to XLS: example code that I'm using:

ExcelPackage pck = new ExcelPackage();
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");
ws.Cells["A1"].LoadFromDataTable(dataTable, true);
FileStream aFile = new FileStream("c:\\data\\excelfile.xls", FileMode.Create);
byte[] byData = pck.GetAsByteArray();
aFile.Seek(0, SeekOrigin.Begin);
aFile.Write(byData, 0, byData.Length);
aFile.Close();

 

When I attempt to open the .xls file with Excel 2003 I'm getting an error message saying "This file is not in a recognizable format". I've copied your code verbatim so I'm sure I've not fat-fingered something.

Jun 27, 2012 at 4:21 PM

No you can't save to xls format.  This code will just save a 2007 formatted spreadsheet with a file extension of xls.

If you only need to read xls files, install the compatibility pack and take a look at excelcnv.exe. There is also ofc.exe, which I believe is just a wrapper around excelcnv.exe.   You can use one of these to convert your file and then read it into epplus.  On a 64 bit 2008 server I had to tell ofc to run in XP SP3 compatibility mode, my programs check for this and sets it to be sure.

http://www.codingforpeanuts.co.uk/2012/06/one-of-my-applications-uses-epplus.html

Aug 2, 2012 at 12:44 PM

HI, this is a very interesting topic which I bump every now and then.

I would request the developers that could they please add a feature to convert the generated .xlsx file to .xls a tleast?

Aug 10, 2012 at 7:28 AM

If you need to read or write XLS (BIFF / Excel 97/2000) files, I recommend NPOI. It's not as straightforward as EPPlus, but does a very good job and is also open source.

http://npoi.codeplex.com/

NPOI has (or had at some point) some support for XLSX as well, but after using it a few weeks, I strongly prefer EPPlus for that.

Aug 14, 2012 at 2:37 PM

I don't agree that the developers should spend time adding the ability to write to xls format.  The new formats are so ubiquitous now that almost everyone either has office 2007 and above, libreoffice or the compatibility packs installed on office 2003.  Only legacy apps that can only read xls format are affected by the lack of this feature and that should be a problem for the maintainers of the legacy application.