var
arr: array[2..8] of variant;
begin
...
arr:=ExcelApp.ActiveSheet.Range[ 'B2:H2' ];
//把2换成i循环处理
...
end;
arr: array[2..8] of variant;
begin
...
arr:=ExcelApp.ActiveSheet.Range[ 'B2:H2' ];
//把2换成i循环处理
...
end;
procedure TForm1.n1Click(Sender: TObject);
var
row,brea:integer;
a,b,c,d,e:shortstring;
begin
if table1.active = True then begin
try
ExcelApplication1.Connect;
Except
ExcelApplication1.free;
Abort;
end;
brea := strtoint(inputbox('输入需导入行数!','行数','10'));
if brea<1 then brea := 10;
ProgressBar1.Visible := True;
ProgressBar1.Max := brea;
ExcelApplication1.Visible[0] := true;
for row := 2 to brea do
begin
a := ExcelWorksheet1.Cells.Item[row,2];
b := ExcelWorksheet1.Cells.Item[row,1];
c := ExcelWorksheet1.Cells.Item[row,3];
d := ExcelWorksheet1.Cells.Item[row,4];
e := ExcelWorksheet1.Cells.Item[row,5];
form1.show;
table1.AppendRecord([a,b,c,d,e]);
ProgressBar1.Position := row-1;
end;
ProgressBar1.Hide;
end;
end;
*****************
var
MSExcel: Variant;
i: Integer;
begin
OpenDialog1.Filter:='*.XLS|*.XLS';
OpenDialog1.DefaultExt:='XLS';
if OpenDialog1.Execute then
begin
MSExcel:=CreateOLEObject('Excel.Application');
MSExcel.WorkBooks.Open(OpenDialog1.FileName);
MSExcel.Visible:=False;
//从有数据的行逐行读入数据
for i:=1 to MSExcel.ActiveSheet.UsedRange.Rows.Count do
begin
Edit2.Text:=Edit2.Text+MSExcel.Cells[i,1].Value;
end;
MSExcel.ActiveWorkBook.Close;
MSExcel.Quit;
end;
end;