• Delphi 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.

  • 相关阅读:
    C语言学习笔记<九>
    C语言学习笔记<六>
    C语言学习笔记<八>
    C语言学习代码〈五〉
    C语言学习笔记<七>
    红队笔记横向移动总结
    pikachu通关
    java线程监控
    项目空负载服务器使用cpu过高
    @NotBlank注解使用不生效的解决办法
  • 原文地址:https://www.cnblogs.com/zhangzhifeng/p/2547572.html
Copyright © 2020-2023  润新知