我在以下帖子中使用 stackoverflow 上概述的 XML 格式生成了一个 excel 文件: Generate excel file in .net
但是,当我在 excel 07 中打开它时,我收到以下消息:
The file you are trying to open, "blah.xls", is in a different format than spefied by the file extension. Verify that the file i snot corrupted and is from a trusted source before opening the file. Do you want to open the file now?
是什么导致了错误消息,我该如何摆脱它?谢谢!
最佳答案
尝试调用文件 blah.xlsx
而不是 blah.xls
。 Excel 显然希望 XML 文件具有“xlsx”扩展名。 “xls”扩展名用于二进制格式文件。
根据您的评论进行编辑:
我错了:xlsx
文件不仅仅是 XML 文件,它们是包含 XML 格式和其他元数据的 zip 存档。总而言之,设置起来有点复杂。我会尝试将文件重命名为 blah.xml
,看看是否可行。否则,恐怕您可能需要查看如何制作这些 zip 文件。有两种选择:
- 使用 Microsoft 的 OOXML SDK:参见 http://msdn.microsoft.com/en-us/library/bb448854.aspx .
- 自己动手(更难)。您必须查看 OOXML standard .第 1 部分包含每个 XML 文件的概述和描述。第 2 部分描述了包格式(即 zip 存档格式)。
xlsx
文件在第 2 部分说明您需要的内容之外还有其他要求,因此请先阅读第 2 部分,然后再阅读第 1 部分。
关于.net - 在 office 07 中打开生成的 excel 文件时出现警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/747227/