Word模板,填充领域,C#.NET [英] Word Template, populate fields, C# .NET

查看:192
本文介绍了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)

推荐答案

您可以XPath数据绑定一个文档的.docx英寸。.docx文件是可以在不净的第三方库被打开的Office Open XML只是一个压缩文件

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

和则可以用在自己的XML的文件格式提供.docx文件。然后,你必须做的唯一一件事就是编辑嵌入XML文件,而不是文件本身。参见:

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-和架构validation.aspx

http://blogs.msdn.com/b/acoat/archive/2007/03/01/linking -word-2007-内容控制到自定义xml.aspx

和一个自定义工具进行绑定:

And a custom tool to do the bindings:

http://dbe.codeplex.com/

您可以正常使用也与Word本身的一些交互的.Net,但我不能帮你。

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

这篇关于Word模板,填充领域,C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆