S
sunhood
Unregistered / Unconfirmed
GUEST, unregistred user!
程序如下:
我把所需要合并的文件组成一个列表放在ListView里
procedure TMaunal_Unite_Form.BitBtn1Click(Sender: TObject);
var
Temp1,Temp2,Temp6,Temp7: OleVariant;
i : Integer;
Template : OleVariant;
TempTemp : OleVariant;
OTrue,OFalse : OleVariant;
begin
inherited;
Cursor := crHourGlass;
try
Wordapplication.Connect;
except
MessageDlg('无法打开Word,请确认已安装Word。', mtError, [mbOk], 0);
Abort;
end;
Template := EmptyParam;
OTrue := True;
OFalse := False;
TempTemp := '';
WordApplication.Documents.Add(Template,OFalse);
for i := 0 to RzListView1.Items.count-1 do
WordApplication.Selection.InsertFile(RzListView1.Items.caption,TempTemp,OFalse,OFalse,OFalse);
//save documnet
try
wordapplication.ChangeFileOpenDirectory(sFilePath );
Temp1 := sFilename ;
Temp2 := wdFormatDocument;
Temp6 := wdOriginalDocumentFormat ;
Temp7 := wdSaveChanges;
WordApplication.ActiveDocument.SaveAs(Temp1,Temp2,OFalse,
TempTemp,OTrue,TempTemp,OFalse,OFalse,OFalse,OFalse,OFalse);
WordApplication.ActiveWindow.Close(Temp7,Temp6);
WordApplication.Quit;
WordApplication.Disconnect;
Cursor := crDefault;
ShowMessage('保存成功');
BitBtn3.Enabled := True;
except
on E: Exception do
begin
Showmessage(E.Message);
WordApplication.Disconnect;
Abort;
end;
end;
end;
我把所需要合并的文件组成一个列表放在ListView里
procedure TMaunal_Unite_Form.BitBtn1Click(Sender: TObject);
var
Temp1,Temp2,Temp6,Temp7: OleVariant;
i : Integer;
Template : OleVariant;
TempTemp : OleVariant;
OTrue,OFalse : OleVariant;
begin
inherited;
Cursor := crHourGlass;
try
Wordapplication.Connect;
except
MessageDlg('无法打开Word,请确认已安装Word。', mtError, [mbOk], 0);
Abort;
end;
Template := EmptyParam;
OTrue := True;
OFalse := False;
TempTemp := '';
WordApplication.Documents.Add(Template,OFalse);
for i := 0 to RzListView1.Items.count-1 do
WordApplication.Selection.InsertFile(RzListView1.Items.caption,TempTemp,OFalse,OFalse,OFalse);
//save documnet
try
wordapplication.ChangeFileOpenDirectory(sFilePath );
Temp1 := sFilename ;
Temp2 := wdFormatDocument;
Temp6 := wdOriginalDocumentFormat ;
Temp7 := wdSaveChanges;
WordApplication.ActiveDocument.SaveAs(Temp1,Temp2,OFalse,
TempTemp,OTrue,TempTemp,OFalse,OFalse,OFalse,OFalse,OFalse);
WordApplication.ActiveWindow.Close(Temp7,Temp6);
WordApplication.Quit;
WordApplication.Disconnect;
Cursor := crDefault;
ShowMessage('保存成功');
BitBtn3.Enabled := True;
except
on E: Exception do
begin
Showmessage(E.Message);
WordApplication.Disconnect;
Abort;
end;
end;
end;