自动创建 Microsoft Word 2007 文档的选项

发布于 2024-08-08 19:21:48 字数 1536 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

感情废物 2024-08-15 19:21:48

看看 Microsoft 的 <强>Office OpenXML SDK。它允许您以编程方式创建 Word 2007 (.docx) 文档,而无需 Office 应用程序。

要使用它,您需要熟悉 OpenXML 文件格式。提供示例的一个很好的起点是 布莱恩·琼斯Erika Ehrli

CodeProject 上的此示例也可能是一个好的开始:Creation of a Word 2007使用 Open XML Format SDK 的文档

我还建议您查看 DocumentReflector,这是 SDK 中包含的一个工具,它可以创建代码以根据现有文档生成特定的 Word 文档。

Have a look at Microsoft's Office OpenXML SDK. It allows you to create Word 2007 (.docx) documents programmatically without the Office applications.

To use it you will need to be familiar with the OpenXML file format. A good starting point also providing examples are the blogs of Brian Jones and Erika Ehrli.

This sample on CodeProject might also be a good start: Creation of a Word 2007 document using the Open XML Format SDK.

I also recommend you to have a look at the DocumentReflector, a tool included within the SDK, that creates the code to produce a certain Word document based on an existing document.

几味少女 2024-08-15 19:21:48

选项,我到目前为止使用:

  1. 你的 - COM 自动化:性能对我来说不是最大的问题,
    只是 COM 自动化的所有丑陋细节,例如死进程、锁定文件……;
    对于某些存在 API 且只有一个人使用该应用程序的任务,
    它仍然是一个选择。
    需要安装Word。
  2. 导入为 HTML 并另存为 Word - 工作速度更快、效果更好,符合预期,
    只要你的Word格式简单并且与HTML标记结构非常匹配
    (例如标题、项目列表)。为了简化处理,模板必须是 HTML,
    通常是针对有限用例的快速破解。
    需要安装Word。
  3. 连接和处理保存为 WordML 的模板:免除 COM 的痛苦
    自动化,但由于 WordML 只是一种伪装成 XML 的二进制格式,因此这通常很痛苦;
    因此,有些任务比使用 Word-API 更复杂。
    尽管如此,我还是更喜欢它而不是1。
    不需要安装 Word。
  4. 正如之前的回答,OpenXML SDK:刚刚开始使用这个,似乎是一个很好的选择
    1 和 3 的折衷方案:在 XML 级别或 API 级别上工作 - 无论哪种方式最适合
    某些特征。
    不需要安装 Word。

Options, I used up to now:

  1. Yours - COM automation: performance wasn't the biggest issue here for me,
    just all the ugly details of COM automation like dead processes, locked files, ...;
    for some tasks where an API exists and as long as only person uses the app,
    its still an option.
    Requires Word installation.
  2. Import as HTML and save as Word - works quick and better as expected,
    as long as your word format is simple and matches HTML markup structure quite well
    (e.g. headers, item lists). To simplify handling, templates have to be HTML then,
    so often a quick hack for a limited use case.
    Requires Word installation.
  3. Concatenate and process templates saved as WordML: saves you the pain of COM
    automation, but since WordML is just a binary format masked as XML, it's often a pain;
    hence some tasks are more complicated than using a Word-API.
    Nevertheless I prefer it over 1.
    Does not require a Word installation.
  4. As in previous answer, OpenXML SDK: just starting to use this, seems to be a good
    compromise of 1 and 3: work on XML level or on API level - whatever fits best for a
    certain feature.
    Does not require a Word installation.
成熟稳重的好男人 2024-08-15 19:21:48

其他建议也很感激

OpenXML SDK 的 Java 等效项是 docx4j(我的项目)和 POI。

使用 docx4j,您可以将宏注入到现有的 docx 中,或者从 dotm 中工作(如 divo 建议的那样)。

other recommendations are appreciated too

The Java equivalents to the OpenXML SDK are docx4j (my project), and POI.

Using docx4j, you can inject macros into an existing docx, or work from a dotm (as divo suggests).

七禾 2024-08-15 19:21:48

Officewriter 是另一种选择。

OfficeWriter API 是一个 .NET 库,允许您生成、
操作并读取您自己的 Excel 和 Word 文档
应用程序。

Officewriter is another option.

The OfficeWriter API is a .NET library that allows you to generate,
manipulate, and read Excel and Word documents from your own
applications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文