delphi调用WORD

来源:互联网 发布:人工智能的危害 编辑:程序博客网 时间:2024/06/07 14:44
 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Word2000, OleServer, StdCtrls, OleCtnrs;

type
  TForm1 = class(TForm)
    WordDoc1: TWordDocument;
    WordApp1: TWordApplication;
    btn1: TButton;
    scrlbx1: TScrollBox;
    olcntnr1: TOleContainer;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
  filename:OleVariant;
begin
   try
     WordApp1.Connect;
   except
     ShowMessage('WORD没有正确安装!');
     exit;
   end;
   filename:='E:\table.doc';
   WordDoc1.Connect;
   WordDoc1.Content.Text:='利用Delphi绘制表格';
   WordDoc1.SaveAs(filename);
   olcntnr1.CreateLinkToFile('E:\table.doc',False);
end;

end.

原创粉丝点击