张
张利中
Unregistered / Unconfirmed
GUEST, unregistred user!
现在我采用delphi自带的三个Excel控件连接Excel文件。
假设文件中有10行数据。那么我怎么用编程的方法得到
当前数据的实际行数(即10)。
我采用下面代码,但得到是错误的。
procedure TForm1.Button1Click(Sender: TObject);
var
Current_File:string;
str:string;
sheet:variant;
i,j:integer;
begin
j:=0;
str:='';
if (combobox1.Text<>'') AND (combobox2.Text<>'') and (combobox3.Text<>'')
AND (combobox4.Text<>'')
then
begin
Current_File:='d:/grade_info/program_file/excel_file/'
+combobox1.text+'_'+combobox2.Text+'_'+combobox3.Text+'_'+combobox4.Text+'.xls';
//启动excel,读取数据
ExcelApplication1.Connect;
ExcelWorkBook1.ConnectTo
(ExcelApplication1.Workbooks.Open(Current_File, EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam, EmptyParam,EmptyParam,0));
ExcelWorkBook1.Activate;
ExcelWorksheet1.ConnectTo(ExcelWorkBook1.ActiveSheet as _WorkSheet);
ExcelWorkSheet1.Activate;
sheet:=ExcelApplication1.ActiveSheet;
for i:=0 to 100 do
begin
if trim(ExcelWorkSheet1.cells.item[i+2,1])<>'' then
str:=trim(ExcelWorkSheet1.cells.item[i+2,1]);
combobox5.Items.Add(str);
j=j+1;
end;
edit2.text:=IntToStr(j);
end;
ExcelWorkSheet1.Disconnect;
ExcelWorkBook1.Disconnect;
ExcelApplication1.Disconnect;
ExcelApplication1.quit;
假设文件中有10行数据。那么我怎么用编程的方法得到
当前数据的实际行数(即10)。
我采用下面代码,但得到是错误的。
procedure TForm1.Button1Click(Sender: TObject);
var
Current_File:string;
str:string;
sheet:variant;
i,j:integer;
begin
j:=0;
str:='';
if (combobox1.Text<>'') AND (combobox2.Text<>'') and (combobox3.Text<>'')
AND (combobox4.Text<>'')
then
begin
Current_File:='d:/grade_info/program_file/excel_file/'
+combobox1.text+'_'+combobox2.Text+'_'+combobox3.Text+'_'+combobox4.Text+'.xls';
//启动excel,读取数据
ExcelApplication1.Connect;
ExcelWorkBook1.ConnectTo
(ExcelApplication1.Workbooks.Open(Current_File, EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam, EmptyParam,EmptyParam,0));
ExcelWorkBook1.Activate;
ExcelWorksheet1.ConnectTo(ExcelWorkBook1.ActiveSheet as _WorkSheet);
ExcelWorkSheet1.Activate;
sheet:=ExcelApplication1.ActiveSheet;
for i:=0 to 100 do
begin
if trim(ExcelWorkSheet1.cells.item[i+2,1])<>'' then
str:=trim(ExcelWorkSheet1.cells.item[i+2,1]);
combobox5.Items.Add(str);
j=j+1;
end;
edit2.text:=IntToStr(j);
end;
ExcelWorkSheet1.Disconnect;
ExcelWorkBook1.Disconnect;
ExcelApplication1.Disconnect;
ExcelApplication1.quit;