用delphi吧一個word文檔追加到另外一個word文檔中

來源:互聯網
上載者:User

uses ComObj;
var WordApp: Variant;
begin
WordApp := CreateOleObject('Word.Application');
WordApp.Documents.open('c:/1.doc');
WordApp.Selection.InsertFile('c:/2.doc','',False,false,false);
WordApp.Selection.InsertFile('c:/3.doc','',False,false,false);
WordApp.ActiveDocument.SaveAs('C:/4.doc');//,'wdFormatDocument',False,'',True,'',False,False,False,False,False);
WordApp.Quit;
OleContainer1.CreateObjectFromFile('c:/4.doc',true);
procedure TFrm_Main.btUniteClick(Sender: TObject);
var
I: Integer ;
DocFileName: String ;
DocFile:OleVariant ;
begin
if lvFileName.Items.Count <1 then
Exit ;
btUnite.Enabled := False ;
try
pnJC.Visible := True ;
Frm_Main.Update ;
try
WordA.Connect ;
WordA.Visible := True;
WordDocument1.ConnectTo(WordA.Documents.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam) );
MixWordWindow('Word 文檔合并器');
for I := 0 to lvFileName.Items.Count -1 do
begin
ProgressBar1.Position := I * 100 div lvFileName.Items.Count ;
Label3.Caption := lvFileName.Items.Item[I].SubItems.Strings[0] ;
Frm_Main.Update ;
DocFileName := lvFileName.Items.Item[I].SubItems.Strings[0] ;
WordA.Selection.InsertFile(DocFileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam) ;
end;
ProgressBar1.Position := 100 ;
if CheckBox1.Checked then
begin
DocFile := edDocFileName.Text ;
WordDocument1.SaveAs(DocFile);
end ;
if CheckBox2.Checked then lvFileName.Items.Clear ;

if (CheckBox3.Checked) and (CheckBox1.Checked) then WordA.Quit ;

WordA.Disconnect ;

if CheckBox1.Checked then
Application.MessageBox(PChar('文檔合并工作已經成功的完成。儲存在' + #13+ edDocFileName.Text ),'完成', MB_OK or MB_ICONINFORMATION)
else
Application.MessageBox(PChar('文檔合并工作已經成功的完成。請及時儲存該文檔!' ),'完成', MB_OK or MB_ICONINFORMATION) ;

if CheckBox1.Checked then
begin
DocCount := DocCount + 1 ;
edDocFileName.Text := ExtractFilePath(edDocFileName.Text) + '合并文檔'+ IntToStr(DocCount) +'.Doc' ;
end;

except
on E: Exception do
begin
Application.MessageBox(PChar('系統在合并Word文檔時發生錯誤,請重試!' + #13 + E.message),'系統錯誤', MB_OK or MB_ICONERROR);
end;//end except On
end;
finally
btUnite.Enabled := True ;
pnJC.Visible := False ;
ProgressBar1.Position := 0 ;
Label3.Caption := '正在啟動 Microsoft Word...' ;
end;
end;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.