如何用delphi编一段能打开word文档并能修改其中的内容的程序,如有详细代码更好!!  谢谢!!!

解决方案 »

  1.   

    最简单的就是用System页面的TOleContainer组件
      

  2.   

    用TOleContainer组件,TOpenDialog组件
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, OleServer, Word2000, OleCtnrs;type
      TForm1 = class(TForm)
        OpenDialog1: TOpenDialog;
        OleContainer1: TOleContainer;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
    if Opendialog1.execute then
    begin
    OleContainer1.CreateObjectFromFile(OpenDialog1.FileName,false);
    Olecontainer1.Doverb(ovShow);
    // OleContainer1.Run;
    end;
    end;
    end.
      

  3.   

    用ole很简单的,装入文件,有个属性改一下(不能不能编辑),就是第一次装入时速度 慢一点,自己研究下,挺有意思的:)
      

  4.   

    把xiguali(西瓜狸) 的程序再充实一下,有了它,应该可以实现楼主的要求了,另外用server控件组里的那些第三方控件也可以,不过用的太久了暂时没找到.......procedure TForm1.Button1Click(Sender: Tobject);
    var MSWord: Variant;
    begin
    MSWord := CreateOLEObject('Word.Application');//连接Word
    MSWord.Documents.Open(FileName:='d:\test.doc', ReadOnly:=True);//打开外部Word文档
    MSWord.Visible := 1;//是否显示文件编辑
    MSWord.ActiveDocument.Range(Start:=0, End:=0);//开始改变的启止位置
    MSWord.ActiveDocument.Range.InsertAfter(Text:='Title');//在Word中增加字符'Title'
    MSWord.ActiveDocument.Range.InsertParagraphAfter;
    MSWord.ActiveDocument.Range.Font.Name := 'Arial';//字体名称
    MSWord.ActiveDocument.Range.Font.Size := 24;//字体大小
    end;