簡體   English   中英

Delphi 5 中的 MS Word 2010 郵件合並

[英]MS Word 2010 mailmerge in Delphi 5

有人可以幫忙嗎?

我繼承了一些用 Delphi 5 編寫的軟件,它允許將數據庫(.ADT 文件)中的成員數據和字段合並到 word 中。

它適用於除 2010 之外的所有 Word 版本,它不會加載任何文檔並顯示錯誤:

“該方法在該對象上不可用”

有人告訴我,解決方案是將預設組件 OpWord 和 OpDataSet 替換為 Ole 變體。 我已經使用 OpWord 這樣做了:

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

並且文檔現在加載但沒有任何合並字段數據。 誰能讓我知道如何從數據庫中提取這些數據,因為 OpDataSet 似乎只是指向表格?

或者任何人都可以提出比我正在嘗試的解決方案更好的解決方案。 我對 Delphi 很陌生,所以我有點過頭了

編輯:(要求的信息)

抱歉,如果需要,我有更多詳細信息和代碼。

這些組件似乎與 TOpExcel、TOpOutlook 等一起屬於名為 OfficePartner 的庫。

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

我希望這有幫助...

這是我用於 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