使用 C# 合并 Office 2007 或 2003 中的字段

发布于 2024-07-13 23:48:07 字数 317 浏览 5 评论 0原文

我想按照以下方式设置一个模板文档:

<前><代码>================ 文档内容 ---------------- 合并字段1 合并字段2 合并字段3 ---------------- 更多文档内容 ===============

然后,我希望能够打开文档,从 C# 数据库中加载 DataTable,并合并中间模板部分中的字段。 DataTable会有多条记录,因此需要合并并输出多个模板来创建一个大文档。 我找不到任何这样做的例子。

I want to set up a template document along the lines of this:

================
Doc content

----------------
Merge Field1
Merge Field2
Merge Field3
----------------

More doc content
================

I then want to be able to open the document, load a DataTable from the database in C# and merge the fields in the template section in the middle. The DataTable will have multiple records so it needs to merge and output multiple templates to create one big document. I can't find any examples of doing this.

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

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

发布评论

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

评论(2

我只土不豪 2024-07-20 23:48:07

不久前我有一份做这件事的工作。 我们使用Word Automation,但它很痛苦(因为Word会做一些疯狂的事情,比如弹出一个模式对话框,这会破坏你的代码)。

我们转而使用 Aspose 库。 我发现它在该领域相当合理且功能齐全(对合并字段有很好的支持)。 然而,它是商业性的。

(我与该公司没有任何关系 - 我只是使用了他们的软件)

编辑:如果您只需要 Word 2007 支持,请不要理会这些人; 有很多免费图书馆。 但对旧版本的支持更难找到

I had a job doing this stuff a while back. We were using Word Automation but it's painful (because Word will do crazy things like pop up a modal dialog which will break your code).

We moved to using the Aspose library. I found it fairly reasonable and quite fully featured in this area (there is good support for merge fields). It is, however, commercial.

(I have no ties to the company - I've just used their software)

Edit: If you only need Word 2007 support, don't bother with these guys; there are plenty of free libraries. Support for older versions is harder to find though

╰◇生如夏花灿烂 2024-07-20 23:48:07

我使用此库生成 MS Word 2007 文档。 希望它能帮助你。
PS 以前这个库是完全免费的,但现在他们也添加了商业版本。 但免费版本包含您所需的所有功能。

I've used this library to generate MS Word 2007 documents. Hope it'll help you.
P.S. Previously this library was completely free but now they've added a commercial version too. But free version contains all necessary features for you.

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