Delphi 5 中的 MS Word 2010 邮件合并
有人可以帮忙吗?
我继承了一些用 Delphi 5 编写的软件,它允许将数据库(.ADT 文件)中的成员数据和字段合并到 word 中使用。
它适用于除 2010 之外的所有版本的 Word,它不会加载任何文档并显示错误:
“该方法在该对象上不可用”
我被告知解决方案是将预设组件 OpWord 和 OpDataSet 替换为 Ole变体。我已经使用 OpWord 这样做了:
wrdApp := CreateOleObject('Word.Application');
现在文档已加载,但没有任何合并字段数据。谁能告诉我如何从数据库中提取这些数据,因为 OpDataSet 似乎只是指向表?
或者任何人都可以提出比我正在尝试的更好的解决方案。我对 Delphi 很陌生,所以我有点不知所措
编辑:(请求的信息)
抱歉,如果需要,我有更多详细信息和代码。
这些组件似乎属于一个名为 OfficePartner 的库,以及 TOpExcel、TOpOutlook 等。
.doc 是从 Form30 上的弹出 ListPane 中选择的,打开并填充表 4 中的合并字段数据。表 1 是成员数据库:
{Use Table4 as we can Set a range on it}
Table4.SetRange([Table1.FieldByName('Member Id').AsString],[Table1.FieldByName('Member Id').AsString]);
{Open Word}
OpWord1.Connected := True;
{Open the Test Document}
OpWord1.OpenDocument(DocumentDirectory + '\' + Form30.ListBox1.Items[Form30.ListBox1.ItemIndex]);
{Populate the Test Document}
OpWord1.ActiveDocument.MailMerge.OfficeModel := OpDataSetModel1;
OpWord1.ActiveDocument.PopulateMailMerge;
OpWord1.ActiveDocument.ExecuteMailMerge;
我希望这会有所帮助...
could anyone help?
I've inherited some software written in Delphi 5 which allows member data and fields from a database (.ADT file) to be used merged in to word.
It works fine with all version of Word except 2010 where it won't load any documents and shows the error:
"That Method is not available on that object"
I have been told the solution is to replace the preset components OpWord and OpDataSet with Ole variants. I have done so with OpWord using:
wrdApp := CreateOleObject('Word.Application');
and the documents now load up but without any merge field data. Can anyone let me know how to extract this data from the database, as the OpDataSet seems to simply just point at the table?
Or can anyone suggest a better solution than the one I'm trying. I'm very new to Delphi so I'm in abit over my head
Edit: (Requested Info)
Sorry I have more details and code if required.
The components appear to belong to a library called OfficePartner along with TOpExcel,TOpOutlook and others.
The .doc is selected from a popup ListPane on Form30, opened and populated with merge field data from Table 4. Table 1 is the members database:
{Use Table4 as we can Set a range on it}
Table4.SetRange([Table1.FieldByName('Member Id').AsString],[Table1.FieldByName('Member Id').AsString]);
{Open Word}
OpWord1.Connected := True;
{Open the Test Document}
OpWord1.OpenDocument(DocumentDirectory + '\' + Form30.ListBox1.Items[Form30.ListBox1.ItemIndex]);
{Populate the Test Document}
OpWord1.ActiveDocument.MailMerge.OfficeModel := OpDataSetModel1;
OpWord1.ActiveDocument.PopulateMailMerge;
OpWord1.ActiveDocument.ExecuteMailMerge;
I hope this helps...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我在 D6 中使用的一个 Word 邮件合并的小程序,它只是一个片段,你必须包含在某个类中,我不再有 Delphi,所以无法编译以确保它工作,无论如何就在这里,希望有帮助:
Here is a little procedure for word mail merge that I used way back for D6, it's a just snippet and you have to include in some class, I don't have Delphi anymore so can't compile to make sure that it works, anyway here it is, hope it helps: