gpt4 book ai didi

c# - 将 xlsx 转换为 xls 问题

转载 作者:行者123 更新时间:2023-11-30 22:14:07 25 4
gpt4 key购买 nike

我正在尝试将 .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?"....

打开时一切正常,但我不明白为什么会这样。我在这个程序中的下一步是将数据从 xls 导入 SQL,但我担心这会导致问题。

这是我调用 SaveAs 方法更改文件扩展名的代码行。

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

我刚开始

wb.SaveAs("filename.xls"); 

在我得到错误后,我做了更多的挖掘并找到了 xlOpenXMLWorkbook,但似乎没有帮助。

任何可以帮助我理解为什么会发生这种情况的信息都将不胜感激。

最佳答案

要保存为电子表格(OpenXml 格式,.xlsx),请使用 XlFileFormat.xlOpenXMLWorkbook:

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

要保存为 Excel 1997-2003 格式(Biff,.xls),请使用 XlFileFormat.xlExcel8:

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

确保您设置了适当的扩展名(.xlsx 或 .xls),否则,您会遇到您描述的错误。

另请参阅我的回答 Excel Interop Save as is giving compatibility checker in excel 2007

关于c# - 将 xlsx 转换为 xls 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18668154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com