简体   繁体   English

Delphi 5 中的 MS Word 2010 邮件合并

[英]MS Word 2010 mailmerge in Delphi 5

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.我继承了一些用 Delphi 5 编写的软件,它允许将数据库(.ADT 文件)中的成员数据和字段合并到 word 中。

It works fine with all version of Word except 2010 where it won't load any documents and shows the error:它适用于除 2010 之外的所有 Word 版本,它不会加载任何文档并显示错误:

"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.有人告诉我,解决方案是将预设组件 OpWord 和 OpDataSet 替换为 Ole 变体。 I have done so with OpWord using:我已经使用 OpWord 这样做了:

wrdApp:= CreateOleObject('Word.Application'); 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?谁能让我知道如何从数据库中提取这些数据,因为 OpDataSet 似乎只是指向表格?

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我对 Delphi 很陌生,所以我有点过头了

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.这些组件似乎与 TOpExcel、TOpOutlook 等一起属于名为 OfficePartner 的库。

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:该.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;

I hope this helps...我希望这有帮助...

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:这是我用于 D6 的文字邮件合并的一个小程序,它只是一个片段,你必须包含在一些 class 中,我没有 Delphi 了,所以无论如何无法编译以确保它工作就是这样,希望对你有帮助:

procedure MailMergeWord;
var
  WordApp: TWordApplication;
  WordDoc: TWordDocument;
  doc : WordDocument;
  FileName: OleVariant;
  xx: integer;
begin
  WordApp := TWordApplication.Create(nil);
  WordApp.ConnectKind := ckNewInstance;
  WordDoc := TWordDocument.Create(WordApp);
  FileName := 'TemplateDoc.doc';

  doc := WordApp.Documents.Open(FileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam
                                 ,EmptyParam,EmptyParam,EmptyParam,EmptyParam
                                 ,EmptyParam);

  WordDoc.ConnectTo(Doc);
  for xx := 1 to WordDoc.Fields.Count do
    WordDoc.Fields.Item(xx).Result.Text := OnWordVariable(WordDoc.Fields.Item(xx).Code.Text);
  WordDoc.PrintOut;
  WordDoc.Free;
  WordApp.Free;
end;


function OnWordVariable(varName: string): string;
begin
  Result := 'Value based on variable name';
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM