7

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)

7
  • is there a macro in the excel file ? Commented Apr 5, 2012 at 15:01
  • Does it work with a .xls extension? Commented Apr 5, 2012 at 15:01
  • @MicahArmantrout: There is not. Just data on multiple tabs. Commented Apr 5, 2012 at 15:02
  • @Sorax: It does...but when the file is opened, there is a The document is not in the format the extension says it is in. Do you trust it? dialog that I'd rather avoid. Commented Apr 5, 2012 at 15:03
  • I haven't used the 2010 interop, I've switched to the OpenXML SDK, but I'm familiar with prior interops and I'm at a loss. What you're doing should work. I wish I could help. Commented Apr 5, 2012 at 15:07

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.