Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save XLS Using Interop Excel

The Current Setup:

So, I can use the following code to save a file as an XLS:

_myWorkbook.SaveAs("FileName.xls", Excel.XlFileFormat.xlWorkbookNormal)

I can also use the following code to save a file as an XLSX (Since I use Office 2010):

_myWorkbook.SaveAs("FileName.xlsx", Excel.XlFileFormat.xlWorkbookDefault)

The Issue:

I have tried (unsuccessfully) to save the file as an XLSX using the following code:

_myWorkbook.SaveAs("FileName.xlsx", Excel.XlFileFormat.xlExcel12)

Why does this not work? Last I checked, Excel 12 was Excel 2007 (a version that supports XLSX). Am I missing something?

(For those interested, I get a This extension can not be used with the selected file type error)

like image 327
Onion-Knight Avatar asked Apr 05 '12 14:04

Onion-Knight


People also ask

How do I save an Excel File as XLS?

Click File > Export > Change File Type. Under Workbook File Types, double-click Excel 97-2003 Workbook (*. xls). In the Save As popup window, choose a folder location for the workbook.


1 Answers

Actually XlFileFormat.xlExcel12 is Excel 12.0 binary format (xlsb) , for OpenXML (i.e. xlsx) you need to use XlFileFormat.xlOpenXMLWorkbook enum value.

For a complete reference see here.

like image 169
Petr Abdulin Avatar answered Oct 21 '22 17:10

Petr Abdulin