以下是我写的代码,在合并的过程中,总是有误,各位大虾指正一下,应该如何来改,数据库名为:word,包含两个字段id,word
代码如下
var
     sfilename,sname:string;
     bs:Tadoblobstream;
     str:string;
     i:integer;
     FileName,AddToRecentFiles:olevariant;
begin
//------------------------------------
 wordapp:= TWordApplication.Create(Application);
    wordapp.Connect;
    wordapp.Visible:=false; //控制文挡是否显示    false为不可显示,true为可以显示
    wordapp.Documents.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam);
    worddoc.ConnectTo(wordapp.ActiveDocument); with adoq do
     begin
     close;
     sql.Clear;
     sql.Add('select * from word');
     open;
     end;
        i:=adoq.RecordCount;
       for i:=0 to adoq.RecordCount-1 do
         begin
            str:=edit1.Text;
            bs:=Tadoblobstream.Create(TBLOBfield(ADOQ.FieldByName('word')),bmread);
      try
           sfilename:=extractfilepath(application.ExeName);
           sname:=ExtractShortPathName(sfilename)+trim(adoq.fieldbyname('id').AsString);
           sname:=sname+'.'+'doc';
           bs.SaveToFile(sname);
           wordapp.Selection.InsertFile(sname,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
            worddoc.ConnectTo(wordapp.ActiveDocument);
      finally
        bs.free;
      end;
      //  adoq.Next;
       FileName := 'C:\Doc2.Doc' ;   //将word文档另存为的文件名
       AddToRecentFiles:=false;
       WordDoc.SaveAs(FileName,AddToRecentFiles);
  //-----------------------------------------
  wordapp.Quit;    //退出word应用程序
 end;
//------------------------------------end;