delphi - 将 dbgrid 中的数据输入到 word 邮件合并中

标签 delphi ms-word outlook mailmerge

我想为一封信创建一个邮件页签,并在每封信上输入不同的姓名和地址。我使用 Microsoft 示例作为基点 http://support.microsoft.com/kb/229310,并根据我的喜好对其进行了自定义。但是当我尝试获取 dbgrid 的选定行或整个数据时,我的问题就出现了。我不知道该怎么做。我的第一个想法是对行数执行 1,然后放下一些 tedit 框并将它们放在等于邮件合并数据的位置,但这仍然一次只执行一个。 dbgrid 与 ms Outlook 相连。 这就是他们填充数据的方式..

// Open the file to insert data
wrdDataDoc := wrdApp.Documents.Open('E:\Temp.doc');
 for iCount := 1 to (DBGrid1.DataSource.DataSet.RecordCount) do
wrdDataDoc.Tables.Item(1).Rows.Add;
FillRow(wrdDataDoc, 2, 'Steve', 'DeBroux',
    '4567 Main Street', 'Buffalo, NY  98052');
// Fill in the data
FillRow(wrdDataDoc, 3, 'Jan', 'Miksovsky',
    '1234 5th Street', 'Charlotte, NC  98765');
FillRow(wrdDataDoc, 4, 'Brian', 'Valentine',
    '12348 78th Street  Apt. 214', 'Lubbock, TX  25874');

那么我如何从 dbgrid 中获取数据并用该信息填充文件?

最佳答案

var
  i: Integer;
  bm: TBookmark;
begin
  DBGrid1.DataSource.DataSet.DisableControls;
  try
    bm := DBGrid1.DataSource.DataSet.GetBookmark;
    try
      i := 0;
      DBGrid1.DataSource.DataSet.First;
      while not DBGrid1.DataSource.DataSet.Eof do begin
        Inc(i);
        FillRow(wrdDataDoc, i,
          DBGrid1.DataSource.DataSet.FieldByName('Name').AsString,
          DBGrid1.DataSource.DataSet.FieldByName('Address1').AsString,
          ..
          );
        DBGrid1.DataSource.DataSet.Next;
      end;
      if Assigned(bm) then
        DBGrid1.DataSource.DataSet.GotoBookmark(bm);
    finally
      DBGrid1.DataSource.DataSet.FreeBookmark(bm);
    end;
  finally
    DBGrid1.DataSource.DataSet.EnableControls;
  end;
end;

关于delphi - 将 dbgrid 中的数据输入到 word 邮件合并中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10372596/

相关文章:

css - 时事通讯 HTML : fonts and vertical align

html - 格式化电子邮件布局问题 Outlook 2013 - Windows 7

plugins - 我应该为 Outlook 插件使用什么存储?

windows - 检测系统启动事件

delphi - Embarcadero 的文档中的 EncodeDateTime 是否错误?

excel - 创建自安装宏?

vba - 使用 VBA 从多个文件中提取表格到 Excel

delphi - 在 Delphi 7 中从字符串中去除非字母数字字符的最快方法是什么?

xml - Delphi XML - 从父节点获取值

vba - Word、Paragraphs.Add 不返回刚刚添加的段落