使用 Open XML SDK 进行邮件合并
我有一个包含 3 列(a、b、c)的 DataTable 和一个设置了相应 MailMerge 字段的 docx 文件。 我想做的是对包含数据的文档执行邮件合并。
假设您可以写入硬盘(如果您需要创建 csv 等文件来进行合并等),您没有有 word、excel 等,Open XML SDK是< /em> 已安装,但同样我们可以安装其他任何东西。
就答案而言,将输入数据转换为所需的数据并不是真正的问题,问题是如何在 Open XML SDK(或其他免费 API)中执行邮件合并。
附带说明一下,输出应该是一个包含 n 页的文件(其中 n 是数据中的行数),即不是 n 个文档(尽管我不介意文档合并是否在最后完成)。
(我应该补充一点,我与 MailMerge 概念无关,例如能够仅进行替换就可以了 - 尽管显然这需要最后将文件合并在一起......)
I have a DataTable with 3 columns (a,b,c) and a docx file with the corresponding MailMerge fields set up. What I'd like to do is perform a Mail Merge on the document with the data.
Presume that you can write to the hard disk (if you need to create a csv etc for doing the merge etc), you don't have word, excel etc, Open XML SDK is installed, but equally we can install anything else.
In terms of the answer, converting the input data to whatever is needed isn't really a problem, the problem is how to perform a mail merge in the Open XML SDK (or other FREE API).
As a side note, the output should be one file with n pages (where n is the number of rows in the data), i.e. not n documents (though I don't mind if the merge of documents is done at the end).
(I should add, I'm not tied to the MailMerge concept, being able to just do a replace for example would work - though obviously that then requires merging the files together at the end...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以一种非常可怕的方式工作 - 基本上 - 目前,算法如下:
合并文档的实际代码来自 Eric White 的博客: http://blogs.msdn.com/ericwhite/archive/2009/02/05/move-insert-delete-文字处理文档中的段落使用-the-open-xml-sdk.aspx
I've got this working in a pretty horrible way - basically - at the moment, the algorithm follows this:
The actual code for merging the documents comes from Eric White's Blog : http://blogs.msdn.com/ericwhite/archive/2009/02/05/move-insert-delete-paragraphs-in-word-processing-documents-using-the-open-xml-sdk.aspx