N
No_Zero
Unregistered / Unconfirmed
GUEST, unregistred user!
数据大概有2W条左右,读取的时候好卡的感觉,花的时间也挺长,不知道什么方法可以提高效率,并防止界面呆住?
程序如下:
procedure TForm1.ck;
var
ep:variant;
c1,c2:integer;
begin
c1:=1;
ep:=createoleobject('excel.application');
ep.visible:=FALSE;
ep.caption:='EXCEL程序';
ep.workbooks.open('D:/My Documents/y6.xls');
showmessage('读取数据中……');
while ep.worksheets[3].Cells[c1,1].value<>'' do //查看数据有多少条
c1:=c1+1;
for c2:=2 to c1 do //循环读取数据到Tstringgrid中
begin
lb1.Cells[0,c2-1]:=inttostr(c2-1);
lb1.Cells[2,c2-1]:=ep.worksheets[3].cells[c2,2].value;
lb1.Cells[1,c2-1]:=ep.worksheets[3].cells[c2,1].value;
lb1.Cells[3,c2-1]:=ep.worksheets[3].cells[c2,3].value;
end;
ep.ActiveWorkBook.Save;
ep.workbooks.close;
ep.quit;
showmessage('数据读取完毕!');
end;
程序如下:
procedure TForm1.ck;
var
ep:variant;
c1,c2:integer;
begin
c1:=1;
ep:=createoleobject('excel.application');
ep.visible:=FALSE;
ep.caption:='EXCEL程序';
ep.workbooks.open('D:/My Documents/y6.xls');
showmessage('读取数据中……');
while ep.worksheets[3].Cells[c1,1].value<>'' do //查看数据有多少条
c1:=c1+1;
for c2:=2 to c1 do //循环读取数据到Tstringgrid中
begin
lb1.Cells[0,c2-1]:=inttostr(c2-1);
lb1.Cells[2,c2-1]:=ep.worksheets[3].cells[c2,2].value;
lb1.Cells[1,c2-1]:=ep.worksheets[3].cells[c2,1].value;
lb1.Cells[3,c2-1]:=ep.worksheets[3].cells[c2,3].value;
end;
ep.ActiveWorkBook.Save;
ep.workbooks.close;
ep.quit;
showmessage('数据读取完毕!');
end;