Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
看看 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.
选项,我到目前为止使用:
只是 COM 自动化的所有丑陋细节,例如死进程、锁定文件……;
对于某些存在 API 且只有一个人使用该应用程序的任务,
它仍然是一个选择。
需要安装Word。
只要你的Word格式简单并且与HTML标记结构非常匹配
(例如标题、项目列表)。为了简化处理,模板必须是 HTML,
通常是针对有限用例的快速破解。
需要安装Word。
自动化,但由于 WordML 只是一种伪装成 XML 的二进制格式,因此这通常很痛苦;
因此,有些任务比使用 Word-API 更复杂。
尽管如此,我还是更喜欢它而不是1。
不需要安装 Word。
1 和 3 的折衷方案:在 XML 级别或 API 级别上工作 - 无论哪种方式最适合
某些特征。
不需要安装 Word。
Options, I used up to now:
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.
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.
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.
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.
OpenXML SDK 的 Java 等效项是 docx4j(我的项目)和 POI。
使用 docx4j,您可以将宏注入到现有的 docx 中,或者从 dotm 中工作(如 divo 建议的那样)。
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).
Officewriter 是另一种选择。
Officewriter is another option.