XLSReadWriteII5导入excel数据
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;
本文来自博客园,作者:liessay,转载请注明原文链接:https://www.cnblogs.com/liessay/p/10011851.html