Word 模板、填充字段、C# .NET
我有一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 .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.