简体   繁体   English

将xlsx转换为xls问题

[英]Convert xlsx to xls issue

I am trying to convert a .xlsx file to .xls and it seems to be working fine, however when I open the .xls file I get a warning message " 我正在尝试将.xlsx文件转换为.xls ,它似乎工作正常,但是当我打开.xls文件时,出现警告消息“

The file you are trying to open 'filename', is in a different format than specified by the file extension. 您尝试打开“文件名”的文件的格式与文件扩展名指定的格式不同。

Verify that the file is not corrupted and >from a trusted source before opening the >file. 在打开>>文件之前,请验证该文件没有损坏,并且>来自受信任的来源。 Do you want to open the file now?".... 您要立即打开文件吗?” ...

Everything looks fine when I open it, but I do not understand why this is happening. 当我打开它时,一切看起来都很好,但是我不明白为什么会这样。 My next step in this program is to import the data from the xls into SQL, but I am afraid this will cause issues for that. 我在该程序中的下一步是将数据从xls导入到SQL中,但是恐怕这会引起问题。

Here is the line of code where I call the SaveAs method to change the file extension of the file. 这是代码行,我在其中调用SaveAs方法来更改文件的文件扩展名。

wb.SaveAs("filename.xls", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);

I initially just had 我最初刚吃过

wb.SaveAs("filename.xls"); 

and after I got the error I did some more digging around and found the xlOpenXMLWorkbook , but does not seem to help. 在收到错误消息后,我做了一些进一步的挖掘,发现了xlOpenXMLWorkbook ,但似乎没有帮助。

Any info that could help me understand why this is happening would be much appreciated. 我们将不胜感激任何能帮助我理解为什么会发生这种情况的信息。

To save as spreadsheet (OpenXml Format, .xlsx ), use XlFileFormat.xlOpenXMLWorkbook : 要另存为电子表格(OpenXml格式, .xlsx ),请使用XlFileFormat.xlOpenXMLWorkbook

wb.SaveAs("filename.xlsx", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);

To save as Excel 1997-2003 format (Biff, .xls ), use XlFileFormat.xlExcel8 : 若要保存为Excel 1997-2003格式(Biff, .xls ),请使用XlFileFormat.xlExcel8

wb.SaveAs("filename.xls", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8);

Make sure you set the appropriate extension (.xlsx or .xls), otherwise, you have the error you described. 确保设置了适当的扩展名 (.xlsx或.xls),否则,将出现您描述的错误。

See also my answer here Excel Interop Save as is giving compatibility checker in excel 2007 在此处查看我的答案Excel Interop另存为在Excel 2007中提供兼容性检查器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM