我正在尝试更新用 Delphi 编写的会员软件,以将邮件合并到 Word2010 中。
然后,对于模板中的每个合并字段名称,我将其替换
wrdApp := CreateOleObject('Word.Application');
wrdDoc := wrdApp.Documents.add();
为表中相应的字段值。
由于之前的回答,我已成功为单个成员完成此操作: Delphi 5 中的 MS Word 2010 mailmerge
但是,我在为表中的所有成员迭代此代码时遇到问题。理想情况下,我需要模板显示在同一文档的新页面上,并显示下一个成员的详细信息。
目前我只能为每个成员覆盖相同的文档,或者每次创建一个新文档。
任何人都可以建议我如何在下一页上重新创建模板、将多个文档合并到同一个文档中或建议一种替代方法。
非常感谢
I am trying to update my membership software written in Delphi, to mailmerge in to Word2010.
I'm using
wrdApp := CreateOleObject('Word.Application');
wrdDoc := wrdApp.Documents.add();
then for each merge field name in a template I'm replacing it with the corresponding field value from a table.
I have successfully done this for single members thanks to a previous answer: MS Word 2010 mailmerge in Delphi 5
However I'm having trouble iterating this code for all members in the table. Ideally I need the template to appear on a new page in the same document with the next members details on.
Currently I can only overwrite the same document for each member, or create a new document each time.
Can anyone advise me how to either recreate the template on the next page, merge multiple documents in to the same one or suggest an alternative method.
many thanks
发布评论
评论(2)
您实际上并没有创建邮件合并。
这是一些可能有帮助的代码(请参阅下面的注释)。它使用 Delphi 的
TWordApplication
组件来处理连接并提供数据类型,但它应该为您提供进入的方向:注意:此代码的大部分是从下载的 示例 我从 Deborah Pate 的 页面。 freeserve.co.uk/" rel="nofollow">网站。 (Deborah 曾经(并且可能仍然是)TeamB 的成员。)我只是将其修改为通过
TWordApplication
连接,并将其更新为在 Delphi XE 下编译。正如我所说,它使用
TWordApplication
建立与 Word 的连接并公开所使用的方法和类型。其他一切都在代码本身中完成。You're not actually creating a mailmerge.
Here's some code (see note below) that might help. It's using Delphi's
TWordApplication
component to handle the connection and provide the datatypes, but it should give you a direction to go in:NOTE: Much of this code was obtained from a downloaded example I got from the Word automation page of Deborah Pate's website. (Deborah was (and may still be) a member of TeamB.) I simply modified it to connect via
TWordApplication
and updated it to compile under Delphi XE.As I said, it's using
TWordApplication
to make the connection to Word and expose the methods and types used. Everything else is done in the code itself.看起来您并没有真正执行邮件合并,而是在搜索和替换之前执行。这是有原因的吗?否则为什么不建立一个“真正的”邮件合并来解决您的问题呢?
It seems you are not really performing a mailmerge but fore of a search and replace. Is there a reason for this? Otherwise why not just set up a 'real' mailmerge which would solve your problems.