码迷,mamicode.com
首页 > 其他好文 > 详细

TXLSReadWriteII2版本导出Excel文件:

时间:2015-09-28 00:05:25      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:

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

 

TXLSReadWriteII2版本导出Excel文件:

标签:

原文地址:http://www.cnblogs.com/chenmfly/p/4842944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!