⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utemplateloader.pas

📁 Delphi/BCB 各种版本都支持的Excel 读写控件.一成功应用在N个项目中 .
💻 PAS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -