delphi 操作word文档

//第一步

try

  wordapplication1.Connect;

except

  wordapplication1.Disconnect;

  messagedlg('请安装Office中的Word软件!',mterror,[mbok],0);

  exit;

end;


// 不显示word

wordapplication1.Visible:=false;


//第二步,添加模版


template:='C:\模版.dot';

   wordapplication1.Documents.Add(template,newtemplate,emptyparam,emptyparam);

   worddocument1.ConnectTo(wordapplication1.Documents.Item(itemindex));


//第三步,获取书签,插入文字

bookmark:='书签';

worddocument1.BookMarks.Item(bookmark).Select;

WordApplication1.Selection.InsertAfter(spSkinEdit1.Text);


//第四步,插入图片


bookmark:='图片1';

worddocument1.BookMarks.Item(bookmark).Select;

LinkToFile := False;

SaveWithDocument := True;

    //FPicture :=

il:= WordApplication1.Selection.InlineShapes.AddPicture(pic_filename1,LinkToFile, SaveWithDocument,EmptyParam);

//调整大小

il.Width:=150;

il.Height:=150;


   //第五步,删除标注

total:=worddocument1.Comments.Count;

while total<>0 do

begin

      worddocument1.comments.item(total).Delete;

     total:=worddocument1.comments.Count;

end;

//第6步 保存,关闭

  worddocument1.SaveAs(FileName);

  

   worddocument1.Close;

   wordapplication1.Disconnect;


你可能感兴趣的:(word,Delphi)