uiwflexcel.pas

来自「Delphi/BCB 各种版本都支持的Excel 读写控件.一成功应用在N个项目」· PAS 代码 · 共 93 行

PAS
93
字号
unit UIwFlexCel;

interface

uses
  Classes, SysUtils, IWAppForm, IWApplication, IWTypes, Controls,
  IWBaseControl, IWControl, IWCompButton, UExcelAdapter, XLSAdapter,
  UCustomFlexCelReport, UFlexCelReport, DB, DBTables, IWCompText, IWGrids,
  IWDBGrids, IWCompLabel, IWCompEdit, UFlexCelImport, UFlxNumberFormat;

type
  TIWForm1 = class(TIWAppForm)
    Report: TFlexCelReport;
    XLSAdapter: TXLSAdapter;
    IWButton1: TIWButton;
    Cust: TTable;
    IWButton2: TIWButton;
    IWLabel2: TIWLabel;
    IWText1: TIWText;
    DataSource1: TDataSource;
    IWButton3: TIWButton;
    IWFile1: TIWFile;
    FlexCelImport: TFlexCelImport;
    IWLabel1: TIWLabel;
    procedure IWButton1Click(Sender: TObject);
    procedure IWButton2Click(Sender: TObject);
    procedure IWButton3Click(Sender: TObject);
  public
  end;

implementation

{$R *.dfm}

uses
  ServerController;

//Note that on linux we can't save to streams.
//The only way there is save the report to a temporary file, and then use
//WebApplication.SendFile instead of WebApplication.SendStream

procedure TIWForm1.IWButton1Click(Sender: TObject);
var
  MemStream: TMemoryStream;
begin
  MemStream:=TMemoryStream.Create;
  try
    Report.SavetoStream(MemStream);
    WebApplication.SendStream(MemStream,'application/vnd.ms-excel','report.xls');
    MemStream:=nil; //If we actually sent the stream, WebApplication.SendStream will free it.
  finally
    FreeAndNil(MemStream);
  end; //finally
end;

procedure TIWForm1.IWButton2Click(Sender: TObject);
var
  MemStream: TMemoryStream;
begin
  MemStream:=TMemoryStream.Create;
  try
    Report.SavetoStream(MemStream);
    WebApplication.SendStream(MemStream,'','report.xls', true); //save as an attachment
    MemStream:=nil; //If we actually sent the stream, WebApplication.SendStream will free it.
  finally
    FreeAndNil(MemStream);
  end; //finally
end;

procedure TIWForm1.IWButton3Click(Sender: TObject);
var
  MemStream: TMemoryStream;
  Color: integer;
begin
  MemStream:=TMemoryStream.Create;
  try
    IWFile1.SaveToStream(MemStream);
    MemStream.Position:=0;
    FlexCelImport.LoadFromStream(MemStream);
    WebApplication.ShowMessage('Cell A1: "'+XlsFormatValue(FlexCelImport.CellValue[1,1],FlexCelImport.CellFormatDef[1, 1].Format,Color)+'"',
                               smAlert);
  finally
    FreeAndNil(MemStream);
  end; //finally
end;

initialization
  TIWForm1.SetAsMainForm



end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?