月
月魔
Unregistered / Unconfirmed
GUEST, unregistred user!
在Word模板中插入书签,书签和数据库中的字段名相同!
然后从数据库中提取记录。替换掉书签。
但是下面的代码只能替换一条记录后,就不会再追加新记录。
各位大侠帮我看看。(代码是东拼西凑的,自己感觉很垃圾)
先谢谢了!
procedure TForm1.Button1Click(Sender: TObject);
var
template, newTemplate, ItemIndex, FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format: OLEVariant;
begin
try
WordApp.Connect;
except
Abort;
end;
WordApp.Visible := True;
WordApp.Caption := '###';
Template := EmptyParam;
NewTemplate := False;
ItemIndex := 1;
FileName := 'f:/a.dot';
ConfirmConversions := False;
ReadOnly := false;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;
WordApp.Documents.Open(FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format, EmptyParam, EmptyParam);
WordDoc.ConnectTo(WordApp.Documents.Item(ItemIndex));
WordApp.Documents.Add(Template, NewTemplate, EmptyParam, EmptyParam);
WordApp.Options.CheckSpellingAsYouType := false;
WordApp.Options.CheckGrammarAsYouType := false;
for i := 0 to DBGrid1.Columns.Count - 1 do
begin
if WordDoc.BookMarks.Exists(DBGrid1.Columns.Items.Title.Caption) then
begin
Template := DBGrid1.Columns.Items.Title.Caption;
WordDoc.BookMarks.Item(Template).Select;
if DBGrid1.Columns.Items.Title.Caption <> null then
begin
WordApp.Selection.InsertAfter(Trim(DBGrid1.Columns.Item.Field.AsString));
end;
end;
end;
end;
如感觉分少,请告知加分方法!再+
然后从数据库中提取记录。替换掉书签。
但是下面的代码只能替换一条记录后,就不会再追加新记录。
各位大侠帮我看看。(代码是东拼西凑的,自己感觉很垃圾)
先谢谢了!
procedure TForm1.Button1Click(Sender: TObject);
var
template, newTemplate, ItemIndex, FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format: OLEVariant;
begin
try
WordApp.Connect;
except
Abort;
end;
WordApp.Visible := True;
WordApp.Caption := '###';
Template := EmptyParam;
NewTemplate := False;
ItemIndex := 1;
FileName := 'f:/a.dot';
ConfirmConversions := False;
ReadOnly := false;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;
WordApp.Documents.Open(FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format, EmptyParam, EmptyParam);
WordDoc.ConnectTo(WordApp.Documents.Item(ItemIndex));
WordApp.Documents.Add(Template, NewTemplate, EmptyParam, EmptyParam);
WordApp.Options.CheckSpellingAsYouType := false;
WordApp.Options.CheckGrammarAsYouType := false;
for i := 0 to DBGrid1.Columns.Count - 1 do
begin
if WordDoc.BookMarks.Exists(DBGrid1.Columns.Items.Title.Caption) then
begin
Template := DBGrid1.Columns.Items.Title.Caption;
WordDoc.BookMarks.Item(Template).Select;
if DBGrid1.Columns.Items.Title.Caption <> null then
begin
WordApp.Selection.InsertAfter(Trim(DBGrid1.Columns.Item.Field.AsString));
end;
end;
end;
end;
如感觉分少,请告知加分方法!再+