K
kaoyan999
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了以下内容,但运行时,提示Range和inserafter方法,automation不支持,
是不是这些方法只适用于Server组件,哪么在用olevariant时应用什么方法,将
数据库导入?
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,ComObj, Db, DBTables;
type
TForm5 = class(TForm)
Button1: TButton;
DataSource1: TDataSource;
Query1: TQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.DFM}
procedure TForm5.Button1Click(Sender: TObject);
var
MSWordlevariant;
n:integer;
begin
try
MSWord := GetActiveOleObject('Word.Application');//判断当前内存中是否存在Word程序
except
try
MsWord := CreateOleObject('Word.Application');
except
Exit;
end;
end;
MSWord.Documents.Add(NewTemplate:=False);// Delphi程序新建Word文稿
MSWord.Visible := 1;
//使Word可见
MSWord.ActiveDocument.SaveAs(FileName:='C:/WINDOWS/Desktop/test.doc');//保存Word文档
n:=0;//query字段N序号
while not Query1.Eofdo
begin
for n:=0 to Query1.FieldCount -1do
begin
MSWord.Documents.Range.InsertAfter(Query1.fields[n].AsString+#13);
end;
Query1.Next;
end;
end;
end.
是不是这些方法只适用于Server组件,哪么在用olevariant时应用什么方法,将
数据库导入?
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,ComObj, Db, DBTables;
type
TForm5 = class(TForm)
Button1: TButton;
DataSource1: TDataSource;
Query1: TQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form5: TForm5;
implementation
{$R *.DFM}
procedure TForm5.Button1Click(Sender: TObject);
var
MSWordlevariant;
n:integer;
begin
try
MSWord := GetActiveOleObject('Word.Application');//判断当前内存中是否存在Word程序
except
try
MsWord := CreateOleObject('Word.Application');
except
Exit;
end;
end;
MSWord.Documents.Add(NewTemplate:=False);// Delphi程序新建Word文稿
MSWord.Visible := 1;
//使Word可见
MSWord.ActiveDocument.SaveAs(FileName:='C:/WINDOWS/Desktop/test.doc');//保存Word文档
n:=0;//query字段N序号
while not Query1.Eofdo
begin
for n:=0 to Query1.FieldCount -1do
begin
MSWord.Documents.Range.InsertAfter(Query1.fields[n].AsString+#13);
end;
Query1.Next;
end;
end;
end.