Save XLS with Interop Excel

Current setting:

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

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

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

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

Problem:

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

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

Why is this not working? The last thing I checked, Excel 12 was Excel 2007 (version that supports XLSX). Did I miss something?

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

+6
source share
1 answer

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

For full reference see here .

+16
source

Source: https://habr.com/ru/post/912504/


All Articles