TXLSReadWriteII 公式计算

Posted 游子日月长

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TXLSReadWriteII 公式计算相关的知识,希望对你有一定的参考价值。

unit Unit1;

 

interface

 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, XLSReadWriteII2, StdCtrls, XLSUtils2;

 

type

  TForm1 = class(TForm)

    aXlsObj: TXLSReadWriteII2;

    Button1: TButton;

    aSaveDialog: TSaveDialog;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.Button1Click(Sender: TObject);

var

  i, j: Integer;

  aFileName, aStampTime: AnsiString;

  aa: TFormulaValue;

begin

  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

 

  end;

 

  try

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

    aXlsObj.Sheets[0].AsWideString[1, 0] := ‘formula‘;

    aXlsObj.Sheets[0].AsWideString[2, 0] := ‘lie1‘;

    aXlsObj.Sheets[0].AsWideString[3, 0] := ‘lie2‘;

    for i:=1 to 10 do

    begin

      aXlsObj.Sheets[0].AsWideString[0, i] := Format(‘%d‘, [i+1]);

      aXlsObj.Sheets[0].AsFormula[1, i] := Format(‘C%d + D%d‘, [i+1, i+1]);

      aXlsObj.Sheets[0].AsFloat[2, i] := ( i * 5);

      aXlsObj.Sheets[0].AsFloat[3, i] := ( i * 4);

    end;

    for i:=1 to 10 do

    begin

      aa := aXlsObj.Sheets[0].AsFormulaValue[1 ,i];

      case aa.ValType of

        fvFloat:   ShowMessage(FloatToStr(aa.vFloat));

      end;

    end;

 

    aXlsObj.Filename := aFileName;

    aXlsObj.Write;

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

  finally

  end;

 

end;

 

end.

  

以上是关于TXLSReadWriteII 公式计算的主要内容,如果未能解决你的问题,请参考以下文章

Delphi TXLSReadWriteII导出Excel

Delphi TXLSReadWriteII2 带的demo中直接编辑XLS文件的例子

RNA-Seq分析RPKM, FPKM, TPM, 计算对比

(译)计算距离方位和更多经纬度之间的点

使用从循环内的代码片段中提取的函数避免代码冗余/计算开销

如何用Python编写代码在Word中实现带公式计算过程的计算书?