zoukankan      html  css  js  c++  java
  • Delphi TXLSReadWriteII2 导出Excel

    TXLSReadWriteII2版本导出Excel文件:

    procedure TForm1.N1Click(Sender: TObject);

    var

      i: Integer;

      aSaveDialog: TSaveDialog;

      aFileName, aStampTime: AnsiString;

      aXlsObj: TXLSReadWriteII2;

      p: PDataRec;

    begin

      aSaveDialog := TSaveDialog.Create(Self);

      try

        aSaveDialog.InitialDir := ExtractFilePath(ParamStr(0));

        aSaveDialog.DefaultExt := 'xls';

        aSaveDialog.Filter := 'Excel文件(*.xls)|*.xls|所有文件(*.*)|*.*';

        aStampTime := FormatDateTime('yyyymmddhhnnss', Now);

        aSaveDialog.FileName := aStampTime;

        if not aSaveDialog.Execute then

          Exit;

        aFileName := aSaveDialog.FileName;

        if aFileName = '' then

          Exit;

      finally

        aSaveDialog.Free;

      end;

      aXlsObj := TXLSReadWriteII2.Create(nil);

      try

        aXlsObj.Sheets[0].AsWideString[0, 0] := 'id';

        aXlsObj.Sheets[0].AsWideString[1, 0] := 'table';

        aXlsObj.Sheets[0].AsWideString[2, 0] := 'kind';

        aXlsObj.Sheets[0].AsWideString[3, 0] := 'rows';

        aXlsObj.Sheets[0].AsWideString[4, 0] := 'times';

        aXlsObj.Sheets[0].AsWideString[5, 0] := 'desc';

        for i:=1 to FDataHash.Count - 1 do

        begin

          p := FDataHash[i];

          aXlsObj.Sheets[0].AsWideString[0, i] := Format('%d', [p.id]);

          aXlsObj.Sheets[0].AsWideString[1, i] := p.table;

          aXlsObj.Sheets[0].AsWideString[2, i] := p.kind;

          aXlsObj.Sheets[0].AsWideString[3, i] := Format('%d', [p.rows]);

          aXlsObj.Sheets[0].AsWideString[4, i] := Format('%d', [p.times]);

          aXlsObj.Sheets[0].AsWideString[5, i] := p.desc;

        end;

        aXlsObj.Filename := aFileName;

        aXlsObj.Write;

        ShowMessage(Format('导出文件'+#13#10+'%s'+#13#10 +'成功!', [aFileName]));

      finally

        aXlsObj.Free;

      end;

    end;

  • 相关阅读:
    svn: E120106: ra_serf: The server sent a truncated HTTP response body.
    HTTP method POST is not supported by this URL解决
    TinyOS文件结构清单解析
    Crush Course 神话学笔记
    Django 入门
    Crush Course 心理学笔记
    网络相关知识汇总链接
    9.21 小程序开发培训讲座
    论文简读之LAIA
    Android studio 的那些坑
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/2547245.html
Copyright © 2011-2022 走看看