SWT OleClientSite:如何在Excel中加载XML文件?

时间:2021-07-01 20:23:12

I have an Excel file in OfficeML format, MyData.xls. Since I upgraded to Office 2007 from Office 2003 I get a warning message saying that the file content does not match the file extension. It seems that OfficeML now must have the extension 'xml'.

我有一个OfficeML格式的Excel文件,MyData.xls。自从我从Office 2003升级到Office 2007后,我收到一条警告消息,指出文件内容与文件扩展名不匹配。看来OfficeML现在必须具有扩展名'xml'。

In my application I use OleClientSite to display the file in an OleFrame object. If I change the file extension to 'xml' then Excel is not started. If I leave the extension as 'xsl' then I get the above warning message.

在我的应用程序中,我使用OleClientSite在OleFrame对象中显示该文件。如果我将文件扩展名更改为“xml”,则表示Excel未启动。如果我将扩展名保留为'xsl',那么我会收到上述警告消息。

How can I force the file with the 'xml' extension to be opened in the OleFrame using Excel?

如何使用Excel强制在OleFrame中打开带有'xml'扩展名的文件?

3 个解决方案

#1


The easiest solution is to switch back to the 2003 format, which should not require any changes to your application. To do this, open your file with the extension set to *.xls. When prompted with the warning ("... do you want to open the file now?"), proceed to open (this is a warning to make sure you don't unintentionally open a macro-enabled file). Once in Excel and the file is open, simply save it as *.xls. This can be done by going to "Office Button / Save As / Excel 97-2003 Workbook".

最简单的解决方案是切换回2003格式,不需要对应用程序进行任何更改。为此,请将扩展名设置为* .xls打开文件。当出现警告提示时(“...你想立即打开文件吗?”),继续打开(这是一个警告,以确保你不会无意中打开一个启用宏的文件)。进入Excel并且文件打开后,只需将其保存为* .xls即可。这可以通过转到“Office按钮/另存为/ Excel 97-2003工作簿”来完成。

Now, the harder solution will be upgrading your application to deal with the new OfficeML format. I don't know about the component you're using, but it will likely still work for some of the binary parts in the new standard (most notably VBA projects), but you're going to have to unpack and start reading XML files.

现在,更难的解决方案是升级您的应用程序以处理新的OfficeML格式。我不知道你正在使用的组件,但它可能仍然适用于新标准中的一些二进制部分(最值得注意的是VBA项目),但是你将不得不解压缩并开始阅读XML文件。

If you haven't already done this, create a new Excel workbook, save it as *.xlsx (the 2007 format) and in Explorer, change its extension to *.zip. Open it up and take a look around. For more in-depth on the files, I would start digesting this MSDN article.

如果您还没有这样做,请创建一个新的Excel工作簿,将其另存为* .xlsx(2007格式),并在资源管理器中将其扩展名更改为* .zip。打开它,看看周围。为了更深入地了解这些文件,我将开始消化这篇MSDN文章。

#2


Maybe I'm missing something, but shouldn't you just use .xslx as your extension? I'm assuming that by OfficeML, you're refering to Office Open XML.

也许我错过了什么,但你不应该只使用.xslx作为你的扩展吗?我假设通过OfficeML,您正在引用Office Open XML。

#3


The <?mso-application progid="Excel.Sheet"?> should be present in the XSL template used. The below link explains clearly how to include the processing instruction. I had to do something similar and it worked for me.

应该出现在使用的XSL模板中。以下链接清楚地解释了如何包含处理指令。我必须做类似的事情,它对我有用。

http://www.shareyourwork.org/roller/ralphsjavablog/entry/generating_excel_sheets_with_xslt

#1


The easiest solution is to switch back to the 2003 format, which should not require any changes to your application. To do this, open your file with the extension set to *.xls. When prompted with the warning ("... do you want to open the file now?"), proceed to open (this is a warning to make sure you don't unintentionally open a macro-enabled file). Once in Excel and the file is open, simply save it as *.xls. This can be done by going to "Office Button / Save As / Excel 97-2003 Workbook".

最简单的解决方案是切换回2003格式,不需要对应用程序进行任何更改。为此,请将扩展名设置为* .xls打开文件。当出现警告提示时(“...你想立即打开文件吗?”),继续打开(这是一个警告,以确保你不会无意中打开一个启用宏的文件)。进入Excel并且文件打开后,只需将其保存为* .xls即可。这可以通过转到“Office按钮/另存为/ Excel 97-2003工作簿”来完成。

Now, the harder solution will be upgrading your application to deal with the new OfficeML format. I don't know about the component you're using, but it will likely still work for some of the binary parts in the new standard (most notably VBA projects), but you're going to have to unpack and start reading XML files.

现在,更难的解决方案是升级您的应用程序以处理新的OfficeML格式。我不知道你正在使用的组件,但它可能仍然适用于新标准中的一些二进制部分(最值得注意的是VBA项目),但是你将不得不解压缩并开始阅读XML文件。

If you haven't already done this, create a new Excel workbook, save it as *.xlsx (the 2007 format) and in Explorer, change its extension to *.zip. Open it up and take a look around. For more in-depth on the files, I would start digesting this MSDN article.

如果您还没有这样做,请创建一个新的Excel工作簿,将其另存为* .xlsx(2007格式),并在资源管理器中将其扩展名更改为* .zip。打开它,看看周围。为了更深入地了解这些文件,我将开始消化这篇MSDN文章。

#2


Maybe I'm missing something, but shouldn't you just use .xslx as your extension? I'm assuming that by OfficeML, you're refering to Office Open XML.

也许我错过了什么,但你不应该只使用.xslx作为你的扩展吗?我假设通过OfficeML,您正在引用Office Open XML。

#3


The <?mso-application progid="Excel.Sheet"?> should be present in the XSL template used. The below link explains clearly how to include the processing instruction. I had to do something similar and it worked for me.

应该出现在使用的XSL模板中。以下链接清楚地解释了如何包含处理指令。我必须做类似的事情,它对我有用。

http://www.shareyourwork.org/roller/ralphsjavablog/entry/generating_excel_sheets_with_xslt