utemplateloader.pas

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

PAS
77
字号
unit UTemplateLoader;
{*******************************************************************************
 This app won't load really anything anywhere...
 To make this work you need to create a table in a db to store the templates.
 The idea of this app is to show how it could be done

 See the doc on TXLSDBTemplateStore for more info on how to use the loaded dbs.
*******************************************************************************}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  {$IFDEF ConditionalExpressions}{$if CompilerVersion >= 14} variants,{$IFEND}{$ENDIF} //Delphi 6 or above
  Dialogs, StdCtrls, XlsBaseTemplateStore, TemplateStore, DB, DBTables;

type
  TFTemplateLoader = class(TForm)
    BtnLoad: TButton;
    Table1: TTable;
    procedure BtnLoadClick(Sender: TObject);
  private
    procedure LoadTemplate(const Template: TXlsTemplate; const FileName: string);
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FTemplateLoader: TFTemplateLoader;

implementation

{$R *.dfm}

procedure TFTemplateLoader.BtnLoadClick(Sender: TObject);
var
  NewTemplate: TXlsTemplate;
begin
  Table1.Open;
  try
    NewTemplate:=TXlsTemplate.Create(nil);
    try
      //Add here all LoadTemplate calls you need
      LoadTemplate(NewTemplate, 'c:\Template1.xls');
      LoadTemplate(NewTemplate, 'c:\Template2.xls');

    finally
      FreeAndNil(NewTemplate);
    end; //finally
  finally
    Table1.Close;
  end; //finally
end;

procedure TFTemplateLoader.LoadTemplate(const Template: TXlsTemplate;
  const FileName: string);
var
  Ms: TMemoryStream;
begin
  Template.FileName:=FileName;
  exit;
  Table1.Insert;
    Table1.FieldValues['FileName']:=ExtractFileName(FileName);
    Ms:=TMemoryStream.Create;
    try
      Template.Storages.WriteData(Ms);
      Ms.Position:=0;
      (Table1.FieldByName('Data') as TBlobField).LoadFromStream(Ms);
    finally
      FreeAndNil(Ms);
    end; //finally
  Table1.Post;
end;

end.

⌨️ 快捷键说明

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