读书人

excel有关问题

发布时间: 2012-03-06 20:47:55 作者: rapoo

excel问题
ExcelApp := CreateOleObject( 'Excel.Application' );
ExcelApp.WorkBooks.Open( excelfile_OpenDialog.FileName );
if Excelapp.Cells[1,1].Value<>'XX' then aa
if Excelapp.Cells[1,2].Value<>'XX' then bb
if Excelapp.Cells[1,3].Value<>'XX' then cc
问题:第三句开始没反应啊,直接就then aa 了根本没判断 ,value的值提取不出来,哪里错了还是什么了····

[解决办法]
procedure TForm1.Button1Click(Sender: TObject);
var
ExcelApp:Variant;
begin
ExcelApp := CreateOleObject( 'Excel.Application' );
try
ExcelApp.Visible:=False;
ExcelApp.WorkBooks.Open('D:\1.xls');
if Excelapp.Cells[1,1].Value<>'XX' then showmessage('aa');
if Excelapp.Cells[1,2].Value<>'XX' then showmessage('bb');
if Excelapp.Cells[1,3].Value<>'XX' then showmessage('cc');
finally
ExcelApp.quit;
end;
end;

有,很正常。。。
[解决办法]
肯定不会自动弹出啊! 就算你输入excelApp.t1234567 := '123456';
也可以编译过去!

还有在最后ExcelApp.quit后还要加一句 ExcelApp := Unassigned;
不加这一句的话!Excel不会正常退出的!你可以试试不加这句
看看内存当中是不是存在一个excel进程!

读书人网 >.NET

热点推荐