为什么不能编译成功(200分救命)(200分)

  • 主题发起人 主题发起人 原谅我今天
  • 开始时间 开始时间

原谅我今天

Unregistered / Unconfirmed
GUEST, unregistred user!
在这段代码中
 excelapp:=texcelapplication.Create(application);
excelwkbook:=texcelworkbook.Create(application);
excelwksheet:=texcelworksheet.Create(application);
excelapp.Connect;
except
messagedlg('excel 可能没有安好!',mterror,[mbyes],0);
abort;
end;
excelapp.Workbooks.Add(emptyparam,0 );//提示说Undeclared identifier: 'emptyparam'
excelwkbook.ConnectTo(excelapp.Workbooks[1]);
excelwksheet.ConnectTo(excelwkbook.Worksheets[1] as_worksheet);//提示说Incompatible types: 'IDispatch' and '_Work
sheet'
救命啊
 
没有use相关的pas 文件
建议先在窗体上添加server页上的几个excel组件,保存后再删除
或者手工添加Excel97 or excel2000 pas文件
 
as //空格问题 _worksheet
 
excelwksheet.ConnectTo(excelwkbook.Worksheets[1] as _worksheet);
 
注意Use相应的单元:Variants OleServer ExcelXP

unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
excelapp: texcelapplication;
excelwkbook: texcelworkbook;
excelwksheet: texcelworksheet;
begin
try
excelapp := texcelapplication.Create(Application);
excelwkbook := texcelworkbook.Create(Application);
excelwksheet := texcelworksheet.Create(Application);
excelapp.Connect;
except
MessageDlg('excel 可能没有安好!', mterror, [mbyes], 0);
Abort;
end;
excelapp.Workbooks.Add(EmptyParam, 0); //提示说Undeclared identifier: 'emptyparam'
excelwkbook.ConnectTo(excelapp.Workbooks[1]);
excelwksheet.ConnectTo(excelwkbook.Worksheets[1] as _worksheet); //
end;

end.

 
把OleServer, Excel2000
都uses上了,但还是Undeclared identifier: 'emptyparam'
 
把OleServer, Excel2000
都uses上了,但还是Undeclared identifier: 'emptyparam'
谁快来救命啊,200分啊
 
加上
var
emptyParam: OleVariant;//或者是Variant;
 
这样编译是通过了
但是运行时出错“ole error 800a034ec”
 

 excelapp:=texcelapplication.Create(application);
excelwkbook:=texcelworkbook.Create(application);
excelwksheet:=texcelworksheet.Create(application);
excelapp.Connect;
except
messagedlg('excel 可能没有安好!',mterror,[mbyes],0);
abort;
end;
excelapp.Workbooks.Add(excelwkbook,0 );//提示说Undeclared identifier: 'emptyparam'
excelwkbook.ConnectTo(excelapp.Workbooks[1]);
excelwksheet.ConnectTo(excelwkbook.Worksheets[1] as _worksheet);//
 
为什么不可以用emptyparam
 
emptyparam好像是在Varints单元中。要 uses variants。如果不在这个单中,可以自
定义
var
emptyparam: olevariant;
使用前写上
emptyparam := null;
 
是否在USE中加入了comobj excel oleserver
 
uses Variants; //D7
EmptyParam是直接可以使用的
 
但是为什么会
但是运行时出错“ole error 800a034ec“
 
ExcelApplication:=TExcelApplication.Create(nil);
ExcelWorkBook:=TExcelWorkBook.Create(nil);
ExcelWorkSheet:=TExcelWorkSheet.Create(nil);
ExcelApplication.Connect;
v1:=EmptyParam;
ExcelApplication.Workbooks.Add(v1,0);
ExcelWorkbook.ConnectTo(ExcelApplication.Workbooks[1]);
ExcelApplication.Visible[LCID]:=True;
ExcelApplication.Caption := '样例表格';
ExcelWorksheet.ConnectTo(ExcelWorkbook.Worksheets[1] as _Worksheet);
 
呵呵,这样保存下来的excel文件是放在哪里的
 
呵呵,给分了,很满意:))
 
后退
顶部