//==============================================================================
// Summeray:根据合成的内容保存一个新的投标文件
//==============================================================================
procedure TSYS_Main_Frm.GetBidDocuMent(aTree:TTreeView;aOLE:TOleContainer);
var
i:integer;
FileName,index:string;
ItemIndex,starts,ends,prop:OleVariant;
begin
ItemIndex:=1; //事先做好的模板文件
aOLE.CreateObjectFromFile('d:/Result.doc',False);
aOLE.DoVerb(1);
//进行页眉,页脚,页码,目录的设置 (目录应在后边设置)
WDA.ConnectTo(IDISPATCH (aOLE.OleObject.Application) as WordApplication );
WDC.ConnectTo(WDA.Documents.Item(ItemIndex));//ItemIndex应始终为1。
WDA.Run('defineBookMark');//在文档的开始位置定义书签
WDA.Application.ActiveWindow.DocumentMap:=True;//显示出word的文档结构图来
for i:=0 to aTree.Items.Count-1 do
begin
if (aTree.Items.Level in[0,1,2]) then continue;
//if aTree.Items.HasChildren then
//begin
prop:='标题 '+IntToStr(aTree.Items.Level-2); //设置标题 注意这里的标题级别的设置是与2有关的
starts:=WDC.Content.End_;
WDC.Range.InsertAfter(aTree.Items.Text);
ends:=WDC.Content.End_;
WDC.Range(starts,ends).Set_Style(prop);
WDC.Range.InsertAfter(#13);//暂时加的
//end;
if not aTree.Items.HasChildren then
begin
index:=TvwGetWord(aTree.Items);
FileName:=GetDocFromDb(index);
try
UnionDocuMents(FileName,aOLE);
except
Application.MessageBox('生成文档过程失败!','提示信息',MB_OK+MB_ICONINFORMATION);
abort;
end;
end
end;//endfor
Bcakspace;
gotoBookmark('BookMark1');//回到定义好的书签的位置(目的是回到文档的首位置)
//应判断一下是否插入目录
WDA.Run('Getindex');//插入目录
if FileExists(getAppName+'temp') then
DeleteFile(getAppName+'temp');
end;
//==============================================================================
//SUMMERAY:合并WORD文档(前提条件是已经打开了一个文档《首文档》)
//Para :FileName(合并文档的名称)
// aOLE(OLE控件)
//ReSult :合并成功返回为True,否则返回为False
//==============================================================================
procedure TSYS_Main_Frm.UnionDocuMents(FileName: string;aOLE:TOleContainer);
var
Range,ConfirmConversioins,Link,Attachment:OLEVariant;
begin
Range:='';
ConfirmConversioins:=false;
Link:=False;
Attachment:=False;
aOle.OleObject.Application.Selection.EndKey(unit := wdStory, Extend := wdMove);//移动光标到末尾
aOle.OleObject.Application.Selection.InsertFile(FileName,Range,
ConfirmConversioins,Link,Attachment);
end;
如果还不行,找(sunhongweisun@yahoo.com.cn)