olecontainer 装入excel,如何获得当前鼠标点击的cell的行和列,程序如下,有问题 ( 积分: 100 )

  • 主题发起人 主题发起人 wanfangme
  • 开始时间 开始时间
W

wanfangme

Unregistered / Unconfirmed
GUEST, unregistred user!
OleContainer1.CreateObjectFromFile('D:/Documents and Settings/test/桌面/111.xls',false);
form1.OleContainer1.run;
OleContainer1.doVerb(-1);
Olecontainer1.AutoActivate:=aaGetFocus;
OleContainer1.SetFocus;
Cur_WorkBook:=OleContainer1.OleObject.Application.WorkBooks.Item[1];
Cur_WorkSheet:=Cur_WorkBook.WorkSheets[1];
//Cur_WorkSheet.Cells[1,1]:=1;
//下面运行报错
I:=OleContainer1.OleObject.Application.ActiveCell.row;
J:=OleContainer1.OleObject.Application.ActiveCell.column;
 
OleContainer1.CreateObjectFromFile('D:/Documents and Settings/test/桌面/111.xls',false);
form1.OleContainer1.run;
OleContainer1.doVerb(-1);
Olecontainer1.AutoActivate:=aaGetFocus;
OleContainer1.SetFocus;
Cur_WorkBook:=OleContainer1.OleObject.Application.WorkBooks.Item[1];
Cur_WorkSheet:=Cur_WorkBook.WorkSheets[1];
//Cur_WorkSheet.Cells[1,1]:=1;
//下面运行报错
I:=OleContainer1.OleObject.Application.ActiveCell.row;
J:=OleContainer1.OleObject.Application.ActiveCell.column;
 
我试了一下:
procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer;
Cur_WorkBook,Cur_WorkSheet:variant;
begin
OleContainer1.CreateObjectFromFile('c:/abc.xls',false);
form1.OleContainer1.run;
OleContainer1.doVerb(-1);
Olecontainer1.AutoActivate:=aaGetFocus;
OleContainer1.SetFocus;
Cur_WorkBook:=OleContainer1.OleObject.Application.WorkBooks.Item[1];
Cur_WorkSheet:=Cur_WorkBook.WorkSheets[1];
//Cur_WorkSheet.Cells[1,1]:=1;
//下面运行不会报错!
I:=OleContainer1.OleObject.Application.ActiveCell.row;
J:=OleContainer1.OleObject.Application.ActiveCell.column;
showmessage(inttostr(i)+','+inttostr(j));
end;
运行一切正常,说明你的程序代码没问题。
你说会报错,把你的错误信息贴出来看看。
 
I:=OleContainer1.OleObject.Application.ActiveCell.row;
J:=OleContainer1.OleObject.Application.ActiveCell.column;

这两句是在另外一个button里执行的,奇怪的很,我先打开这个excel,然后随便点一个cell,然后再点这个button,就报错了,我觉得是因为我点击cell后除了什么问题
 
接受答案了.
 
谢谢 younghat
 
后退
顶部