procedure TForm1.Button1Click(Sender: TObject);
var
xls: TXLSReadWriteII5;
openFile: TOpenDialog;
Rows, Cols: Integer; //rows行数,cols列数
begin
xls := TXLSReadWriteII5.Create(Self); //创建实例
openFile := TOpenDialog.Create(Self);
openFile.Filter := 'Excel|*.xlsx';
openFile.DefaultExt := 'xlsx';
try
if openFile.Execute() then
begin
xls.Filename := openFile.FileName; //读取文件名
xls.Clear;
xls.Read;
StringGrid1.RowCount := xls.Sheets[0].LastRow + 1; //设置stringgrid总行数
StringGrid1.ColCount := xls.Sheets[0].LastCol + 1; //设置stringgrid总列数
for Rows := 0 to xls.Sheets[0].LastRow do
begin
for Cols := 0 to xls.Sheets[0].LastCol do
begin
StringGrid1.Cells[Cols, Rows] := xls.Sheets[0].AsString[Cols, Rows];
end;
end;
end;
finally
xls.Free;
openFile.Free;
end;
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.045282125473022 seconds