不好意思,昨天没有注意看,以为你只要CB的代码,
帮你搞定了,你自己想办法转化成C语言吧!
需要生成了的测试程序(delphi版)给个Email发给你!
呵呵,给101RMB 就帮你找人转化成CB(开个玩笑)
实现思路是:依次打开1文档,将其内容存入临时文件,然后再打开2文档,再添入临时文件中,再开3,再存...,最后完成需要的合并后临时文件写入doc文档。这样就实现了两个文档合并到1个文档。其实Borland已经在她的控件里面已经封装了很多功能,多看帮助和自带的Demo。
程序里主要用到TWordDocument 和 WordApplication,我想CB里面的控件也应该差不多的吧
-------------------------------------------------
unit Unit1;
{
演示如何将3个word文档(1.doc 2.doc 3.doc)合并到一个word文档(保存文件.doc)
中,为此,您除了需要添加所要的控件外,还需在本程序目录下建立三个word文档
(1.doc 2.doc 3.doc)
程序在 windows2000 professional + delphi 6.0 下调试通过
winsong 2006-06-07
[成功将三个1.09MB的带图片doc合并]
}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Word2000, OleServer, ComCtrls;
type
TFrom1 = class(TForm)
Button1: TButton;
WordDocument1: TWordDocument;
Label1: TLabel;
ProgressBar1: TProgressBar;
CheckBox1: TCheckBox;
Edit1: TEdit;
ListBox1: TListBox;
WordApplication1: TWordApplication;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
From1: TFrom1;
implementation
{$R *.dfm}
procedure TFrom1.FormCreate(Sender: TObject);
begin
CheckBox1.Caption := '保存DOC文件在:';
CheckBox1.Enabled := true;
Edit1.Text := ExtractFilePath(Application.EXEName) + '保存文件.doc';
Button1.Caption := '开始合并';
ListBox1.Clear;
ListBox1.Items.Insert(0, ExtractFilePath(Application.EXEName) + '1.doc');
ListBox1.Items.Insert(1, ExtractFilePath(Application.EXEName) + '2.doc');
ListBox1.Items.Insert(2, ExtractFilePath(Application.EXEName) + '3.doc');
end;
procedure TFrom1.Button1Click(Sender: TObject);
var
I,do
cCount: Integer;
do
cFileName: String;
do
cFile: OleVariant;
begin
do
cCount := 0;
if ListBox1.Items.Count <1 then
Exit;
Button1.Enabled := False;
try
From1.Update;
try
WordApplication1.Connect ;
WordApplication1.Visible := True;
WordDocument1.ConnectTo(WordApplication1.Documents.Add(EmptyParam,
EmptyParam, EmptyParam, EmptyParam));
for I := 0 to ListBox1.Items.Count -1do
begin
do
cCount :=do
cCount + 1;
ProgressBar1.Position := I * 100 div ListBox1.Items.Count;
Label1.Caption := ListBox1.Items.Strings;
From1.Update;
do
cFileName := ListBox1.Items.Strings;
WordApplication1.Selection.InsertFile(DocFileName, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);//关键 写入
end;
ProgressBar1.Position := 100;
if CheckBox1.Checked then
begin
do
cFile := Edit1.Text;
WordDocument1.SaveAs(DocFile);//关键 保存合并后的文件
end;
WordApplication1.Disconnect ;
if CheckBox1.Checked then
Application.MessageBox(PChar('文档合并工作已经成功的完成。保存在'
+ #13+ Edit1.Text ),'完成', MB_OK or MB_ICONINFORMATION)
else
Application.MessageBox(
PChar('文档合并工作已经成功的完成。请及时保存该文档!'),
'完成', MB_OK or MB_ICONINFORMATION);
if CheckBox1.Checked then
begin
Edit1.Text := ExtractFilePath(Application.EXEName)
+ '合并文档' + 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
Button1.Enabled := True;
ProgressBar1.Position := 0;
Label1.Caption := '正在启动 Microsoft Word...';
end;
end;
end.
--------------------------------------------------------------