Word 模板、填充字段、C# .NET

发布于 2024-09-14 12:21:45 字数 187 浏览 1 评论 0原文

我有一个Word文档(docx格式),我需要用字典中的数据填充它。字典的键将是要填充的单词字段。我想知道执行此操作的最佳方法是什么(书签、邮件合并字段等)?我对书签做了一些工作,但我希望能够重用某些字段(例如“first_name”字段等),书签是唯一的(或者我似乎是这么认为的)。
关于如何执行此操作的几行代码将非常有帮助。 (c#.net 4.0)

I have a word document (docx format) that I need to populate with data from a dictionary . The key of the dict will be the word field to be populated. I was wondering what is the best way to do this (bookmarks, mail merge fields, etc)? I did a little work with Bookmarks, but I would like to be able to reuse some of the fields (like "first_name" field etc), bookmarks are unique (or I seem to think so).
A few lines of code on how to do this would be really helpful. (c# .net 4.0)

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

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

发布评论

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

评论(1

亚希 2024-09-21 12:21:45

您可以在 .docx 文档中进行 xpath 数据绑定。 .docx 文件只是 Office Open XML 中的压缩文件,无需第三方库即可在 .Net 中打开。

http://msdn.microsoft.com/ en-us/library/system.io.packaging.package.open.aspx

然后您可以为 .docx 文件提供您自己格式的 XML 文件。那么您唯一需要做的就是编辑嵌入的 XML 文件而不是文档本身。请参阅:

http://blogs.msdn.com/b/mikeormond/archive/2008/06/20/word-2007-content-controls-databinding-and-schema-validation.aspx

http ://blogs.msdn.com/b/acoat/archive/2007/03/01/linking-word-2007-content-controls-to-custom-xml.aspx

以及用于进行绑定的自定义工具:

http://dbe.codeplex.com/

您还可以正确地使用与 Word 本身的一些 .Net 交互但我帮不了你。

You can make xpath data bindings in a .docx document. A .docx file is just a zipped file in the Office Open XML which can be opened in .Net without third-party libraries.

http://msdn.microsoft.com/en-us/library/system.io.packaging.package.open.aspx

And you can then supply the .docx file with a XML file in your own format. Then the only thing you have to do is to edit the embedded XML file and not the document itself. See:

http://blogs.msdn.com/b/mikeormond/archive/2008/06/20/word-2007-content-controls-databinding-and-schema-validation.aspx

http://blogs.msdn.com/b/acoat/archive/2007/03/01/linking-word-2007-content-controls-to-custom-xml.aspx

And a custom tool to do the bindings:

http://dbe.codeplex.com/

You could properly also use some .Net interaction with Word itself but I can't help you with that.

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