delphi XLSReadWriteII5导入excel数据  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi 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;



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.045282125473022 seconds