我的目的:做一个把数据生成报表的dll
我的想法:由于做dll不能用控件,所以我想把数据通过dll传递到word,然后把word做成报表格式,我先做了个新建word的代码
我的代码:
procedure report(fieldvalue:array of String;
fieldname:array of String;fieldcount:Integer;
recordcount:Integer);
var
wApp:Variant;//代表Word的变体类型变量
WordApp1:TWordApplication;//word程序
WordDocument1:TWordDocument;//word文档
Template,NewTemplate,documenttype,visible1:OleVariant;
itemIndex,filename:OleVariant;
begin
//打开word
try //测试当前是否运行了Word
wApp:=GetActiveOleObject('word.Application');
except//未运行则运行之
wApp:=CreateOleObject('Word.Basic');
end;
try
//连接到Word
WordApp1.Connect;
except
Beep;
MessageDlg('不能生成文档,请确认是否安装了Word 2000!', mtError, [mbOK], 0);
Abort;
end;
WordApp1.Visible:=true;//显示Word
//通过模板新建文档
//Template := EmptyParam; //使用空白文档,即“Normal.dot”模板
Template:='D:\Gathersdatabase\yinyong\word.dot';//文档模板
NewTemplate:=false;//新建文档的类型,True表示为模板,False表示为文档
documenttype:=wdNewBlankDocument;//文档类型,默认为空白文档
visible1:=false;//打开的窗口是否可见
wordapp1.Documents.Add(Template,NewTemplate,documenttype,visible1);
//连接到新建的文档
itemIndex := 1;//文档号
WordDocument1.ConnectTo(WordApp1.Documents.Item(itemIndex));
//文档另存为
filename:='a.doc';
WordDocument1.SaveAs(filename);
end;
我的问题:
1、程序运行到WordApp1.Connect;就报错,说内存地址出错,这是不是因为我没装word2000,我装的是word xp
2、代码其他地方还有什么问题吗
3、生成报表还有其他不用控件的方法吗
我的想法:由于做dll不能用控件,所以我想把数据通过dll传递到word,然后把word做成报表格式,我先做了个新建word的代码
我的代码:
procedure report(fieldvalue:array of String;
fieldname:array of String;fieldcount:Integer;
recordcount:Integer);
var
wApp:Variant;//代表Word的变体类型变量
WordApp1:TWordApplication;//word程序
WordDocument1:TWordDocument;//word文档
Template,NewTemplate,documenttype,visible1:OleVariant;
itemIndex,filename:OleVariant;
begin
//打开word
try //测试当前是否运行了Word
wApp:=GetActiveOleObject('word.Application');
except//未运行则运行之
wApp:=CreateOleObject('Word.Basic');
end;
try
//连接到Word
WordApp1.Connect;
except
Beep;
MessageDlg('不能生成文档,请确认是否安装了Word 2000!', mtError, [mbOK], 0);
Abort;
end;
WordApp1.Visible:=true;//显示Word
//通过模板新建文档
//Template := EmptyParam; //使用空白文档,即“Normal.dot”模板
Template:='D:\Gathersdatabase\yinyong\word.dot';//文档模板
NewTemplate:=false;//新建文档的类型,True表示为模板,False表示为文档
documenttype:=wdNewBlankDocument;//文档类型,默认为空白文档
visible1:=false;//打开的窗口是否可见
wordapp1.Documents.Add(Template,NewTemplate,documenttype,visible1);
//连接到新建的文档
itemIndex := 1;//文档号
WordDocument1.ConnectTo(WordApp1.Documents.Item(itemIndex));
//文档另存为
filename:='a.doc';
WordDocument1.SaveAs(filename);
end;
我的问题:
1、程序运行到WordApp1.Connect;就报错,说内存地址出错,这是不是因为我没装word2000,我装的是word xp
2、代码其他地方还有什么问题吗
3、生成报表还有其他不用控件的方法吗
可以不用任何控件直接写VBA代码,但没有任何提示,用了控件可能反而不好
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB,comobj, OleServer, Word2000;