在Delphi中使用Office控件,如何给word加水印(或背景)?

解决方案 »

  1.   

    implementationuses ComObj;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      oWord, oDoc: OleVariant;
    begin
      oWord := CreateOleObject('Word.Application');
      oDoc := oWord.Documents.Open('C:\Test\a.doc');  oDoc.ActiveWindow.View.SeekView := 1;//WdSeekView.wdSeekPrimaryHeader
      oDoc.ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddPicture('C:\Test\a.jpg', False, True, 0, 0, 100, 100);
      
      oDoc.Close(True);
      oWord.Quit(False);  ShowMessage('OK');
    end;
      

  2.   

    恩,好的,但我这里这句“oDoc.ActiveWIndow.ActivePane.Selection.HeaderFooter.Shapes.AddPicture('F:\jpg',False,True);",报错了
      

  3.   

    F:\jpg是什么?应该是个图片文件路径阿,比如F:\a.jpg
      

  4.   

    最后一个参数 Anchor 赋什么值
      

  5.   

    赋一个Range范围图片地址写什么都不能去掉,要调用Delete方法
      

  6.   

    我原来从来没用过这个操作word的方法,编码的时候又没有提示,再请问一下:  oDoc.ActiveWIndow.ActivePane.Selection.HeaderFooter.Shapes.Delete ,是不是这样写