Delphi 5中的MS Word 2010 mailmerge [英] MS Word 2010 mailmerge in Delphi 5

查看:50
本文介绍了Delphi 5中的MS Word 2010 mailmerge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮忙吗?

我继承了一些用Delphi 5编写的软件,该软件允许将来自数据库(.ADT文件)的成员数据和字段合并成word.

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.

它可以在Word的所有版本上正常工作,但2010年除外,因为它不会加载任何文档并显示错误:

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"

有人告诉我解决方案是用Ole变体替换预设组件OpWord和OpDataSet.我已经使用OpWord做到了:

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');

wrdApp := CreateOleObject('Word.Application');

,现在可以加载文档,但没有任何合并字段数据.任何人都可以让我知道如何从数据库中提取此数据,因为OpDataSet似乎只是指向表?

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?

或者有人可以提出比我正在尝试的解决方案更好的解决方案.我是Delphi的新手,所以有点不知所措

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

(请求的信息)

抱歉,如果需要,我还有更多详细信息和代码.

Sorry I have more details and code if required.

这些组件似乎与TOpExcel,TOpOutlook等一起属于一个名为OfficePartner的库.

The components appear to belong to a library called OfficePartner along with TOpExcel,TOpOutlook and others.

.doc是从Form30上的弹出列表窗格中选择的,用表4中的合并字段数据打开并填充.表1是成员数据库:

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...

推荐答案

这里是我用于D6的单词邮件合并的一个小程序,它只是一个片段,您必须将其包含在某个类中,我不知道.不再有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:

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;

这篇关于Delphi 5中的MS Word 2010 mailmerge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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