gpt4 book ai didi

java - 在 Java 中使用 Eclipse SWT OleClientSite 打开带有 .doc 扩展名的 Word 文档

转载 作者:行者123 更新时间:2023-11-29 08:50:19 25 4
gpt4 key购买 nike

我正在开发一个程序,该程序使用 Eclipse SWT OleClientSite(在 Windows 7 中)在 RCP 应用程序中打开 Word 文档。在过去的两年中,该程序调用了以下构造函数:

OleClientSite clientSite = new OleClientSite(oleFrame, SWT.NULL, new File(documentFileName));

自 SWT 的最新更新以来,此构造函数现在在尝试打开带有“.doc”扩展名的 Word 文档时抛出异常。带有“.docx”扩展名的 Word 文档仍然可以正常运行。问题似乎是 OleClientSite 没有正确地将“.doc”识别为 Word 扩展名,因为使用以下构造函数显式输入此信息有效:

OleClientSite clientSite = new OleClientSite(oleFrame, SWT.NULL, "Word.Document", new File(documentFileName));

然而,此构造函数带有警告,声明永远不会使用它:

IMPORTANT:This method is not part of the public API for OleClientSite. It is marked public only so that it can be shared within the packages provided by SWT. It is not available on all platforms, and should never be called from application code.

奇怪的是,尽管这个构造函数明确表示永远不应该使用它,但它是 used on the Eclipse SWT Snippets Website as an example of how to open a .doc file ...

如果有人有任何指点,我将不胜感激。到目前为止,我的选择似乎是要么禁止我的用户使用“.doc”文件,要么回滚到旧版本的 SWT。

最佳答案

当前的 Eclipse 版本支持从导航器 View 打开 Word 文档 (*.doc)。它使用 org.eclipse.ui.internal.editorsupport.win32.OleEditor 类在编辑器部分打开文档。我建议您查看 [1] 中的代码并根据您的场景调整所需的部分。

[1] http://git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/bundles/org.eclipse.ui.win32/src/org/eclipse/ui/internal/editorsupport/win32/OleEditor.java

关于java - 在 Java 中使用 Eclipse SWT OleClientSite 打开带有 .doc 扩展名的 Word 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23054905/

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