📄 ufldemo.pas
字号:
unit UFlDemo;
{$IFDEF LINUX}{$INCLUDE ../../FLXCONFIG.INC}{$ELSE}{$INCLUDE ..\..\FLXCONFIG.INC}{$ENDIF}
{$IFDEF ConditionalExpressions}{$if CompilerVersion >= 14} //Delphi 6 or above
{$WARN UNIT_PLATFORM OFF}
{$IFEND} {$ENDIF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, ActnList, ImgList, ToolWin, TemplateStore,
XLSAdapter, UExcelAdapter, OLEAdapter, UFlexCelImport, UFlexcelReport,
UReport, UFlDemoData, ShellApi, Grids, DBCtrls,
UFlDemoEdit, UWaitCursor, UExcelEdit, Menus, FileCtrl,
UFlxMessages, UCustomFlexcelReport, UFlxFormats;
type
TMain = class(TForm)
ActionList: TActionList;
ActionClose: TAction;
ActionReport: TAction;
ActionUseOle: TAction;
ActionUseNative: TAction;
ActionHtml: TAction;
ActionProtect: TAction;
ActionViewTemplateExcel: TAction;
ActionUseTStore: TAction;
Panel1: TPanel;
Splitter1: TSplitter;
ListDemos: TTreeView;
Tabs: TPageControl;
TabSheet1: TTabSheet;
Panel2: TPanel;
TxtWelcome: TRichEdit;
TabSheet2: TTabSheet;
Panel3: TPanel;
Label3: TLabel;
TabSheet3: TTabSheet;
Panel4: TPanel;
Label2: TLabel;
TxtSimpleDemo: TRichEdit;
TabSheet4: TTabSheet;
Panel5: TPanel;
Label1: TLabel;
TxtVarArr: TRichEdit;
Panel6: TPanel;
Label4: TLabel;
TabSheet5: TTabSheet;
Panel7: TPanel;
Label5: TLabel;
TxtDbDemo: TRichEdit;
Panel8: TPanel;
Label6: TLabel;
LookupCust: TDBLookupComboBox;
TabSheet6: TTabSheet;
Panel9: TPanel;
Label7: TLabel;
TxtMultMast: TRichEdit;
TabSheet7: TTabSheet;
Panel10: TPanel;
Label8: TLabel;
TxtSheets: TRichEdit;
TabSheet8: TTabSheet;
TabSheet9: TTabSheet;
TabSheet10: TTabSheet;
TabSheet11: TTabSheet;
TabSheet12: TTabSheet;
TabSheet13: TTabSheet;
ToolBar: TToolBar;
BtnUseNative: TToolButton;
BtnUseOle: TToolButton;
ToolButton5: TToolButton;
BtnHTML: TToolButton;
BtnProtect: TToolButton;
BtnUseTStore: TToolButton;
ToolButton2: TToolButton;
BtnReport: TToolButton;
BtnViewTemplate: TToolButton;
BtnClose: TToolButton;
StatusBar: TStatusBar;
Panel11: TPanel;
Label9: TLabel;
TxtFishFacts: TRichEdit;
PageControl1: TPageControl;
TabSheet15: TTabSheet;
TabSheet16: TTabSheet;
GridVarArray1: TStringGrid;
GridVarArray2: TStringGrid;
Panel12: TPanel;
Label10: TLabel;
TxtPivot: TRichEdit;
Panel13: TPanel;
Label11: TLabel;
TxtEvents: TRichEdit;
Panel14: TPanel;
Label12: TLabel;
TxtCustom: TRichEdit;
Label13: TLabel;
edSQL: TMemo;
Panel15: TPanel;
Label14: TLabel;
TxtReadFile: TRichEdit;
ToolButton1: TToolButton;
TabSheet17: TTabSheet;
Panel16: TPanel;
Label15: TLabel;
TxtCharts: TRichEdit;
Panel17: TPanel;
Label16: TLabel;
TxtImport: TRichEdit;
TxtReport: TRichEdit;
ActionPreview: TAction;
TabSheet14: TTabSheet;
Panel18: TPanel;
Label17: TLabel;
TxtImgDemo: TRichEdit;
Panel19: TPanel;
Label18: TLabel;
edMyImage: TEdit;
btnOpenMyImage: TButton;
PopViewTemplate: TPopupMenu;
VievwithExcel1: TMenuItem;
Openwithinternaleditor1: TMenuItem;
ActionViewTemplateInternal: TAction;
TabSheet18: TTabSheet;
TxtSideBySide: TRichEdit;
Label19: TLabel;
PopReport: TPopupMenu;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
about: TTabSheet;
PopupMenu1: TPopupMenu;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
Panel20: TPanel;
Label20: TLabel;
TxtAbout: TRichEdit;
TabSheet19: TTabSheet;
TxtMemory: TRichEdit;
Label21: TLabel;
Panel21: TPanel;
Label22: TLabel;
ActionAutoPrint: TAction;
GridMemory: TStringGrid;
PrintWARNING1: TMenuItem;
N1: TMenuItem;
TestAll1: TMenuItem;
ActionTestAll: TAction;
TabSheet20: TTabSheet;
Panel22: TPanel;
Label23: TLabel;
TxtCreateFile: TRichEdit;
ActionFastCount: TAction;
ToolButton3: TToolButton;
ActionReportToStream: TAction;
Reporttostream1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure ListDemosChange(Sender: TObject; Node: TTreeNode);
procedure ActionCloseExecute(Sender: TObject);
procedure ActionReportUpdate(Sender: TObject);
procedure ActionUseOleExecute(Sender: TObject);
procedure ActionHtmlUpdate(Sender: TObject);
procedure ActionViewTemplateExcelUpdate(Sender: TObject);
procedure ActionUseTStoreExecute(Sender: TObject);
procedure ActionUseNativeExecute(Sender: TObject);
procedure ActionViewTemplateExcelExecute(Sender: TObject);
procedure ActionReportExecute(Sender: TObject);
procedure ActionPreviewUpdate(Sender: TObject);
procedure ActionPreviewExecute(Sender: TObject);
procedure btnOpenMyImageClick(Sender: TObject);
procedure ActionViewTemplateInternalExecute(Sender: TObject);
procedure ActionAutoPrintExecute(Sender: TObject);
procedure ActionTestAllExecute(Sender: TObject);
procedure ActionFastCountExecute(Sender: TObject);
procedure ActionReportToStreamUpdate(Sender: TObject);
procedure ActionReportToStreamExecute(Sender: TObject);
private
DemoEdit: TDemoEdit;
DlgReport: TReport;
Directory: string;
DataStream: TFileStream;
procedure FillGridVarArray(const GridVarArray: TStringGrid);
procedure DoReport(const Preview: boolean; const Automatic: boolean; const SendToStream: boolean=false);
procedure DoImport;
procedure DoCreateFile(const Automatic: boolean);
procedure FillGridMemory(const GridMemory: TStringGrid);
procedure RepSimpleDemoGetOutStream(Sender: TObject;
const FileFormat: Integer; var OutStream: TStream);
procedure TestImages(const Fi: TFlexCelImport);
{ Private declarations }
public
{ Public declarations }
end;
var
Main: TMain;
implementation
{$R *.DFM}
procedure TMain.FillGridVarArray(const GridVarArray: TStringGrid);
var
i,k: integer;
begin
for i:=1 to GridVarArray.ColCount-1 do GridVarArray.Cells[ i , 0]:= chr(ord('A')+i-1);
for i:=1 to GridVarArray.RowCount-1 do GridVarArray.Cells[ 0 , i]:= IntToStr(i+3);
for i:=1 to GridVarArray.ColCount-1 do
for k:=1 to GridVarArray.RowCount-1 do
GridVarArray.Cells[ i , k]:= IntToStr(Random(5));
GridVarArray.Cells[3,2]:='FlexCel';
end;
procedure TMain.FillGridMemory(const GridMemory: TStringGrid);
var
i: integer;
begin
GridMemory.RowCount:=500;
GridMemory.Cells[0,0]:='Number';
GridMemory.Cells[1,0]:='Name';
GridMemory.Cells[2,0]:='Date';
GridMemory.Cells[3,0]:='Sex';
for i:=1 to GridMemory.RowCount-1 do
begin
GridMemory.Cells[ 0 , i]:= IntToStr(i);
GridMemory.Cells[ 1 , i]:= 'Test'+IntToStr(i);
GridMemory.Cells[ 2 , i]:= DateToStr(Now-random(365*50));
if Random(2)=0 then GridMemory.Cells[ 3 , i]:= 'M' else GridMemory.Cells[ 3 , i]:= 'F';
end;
GridMemory.Cells[1,1]:='Adrian';
GridMemory.Cells[2,1]:='8/9/1972';
GridMemory.Cells[3,1]:='M';
GridMemory.Cells[1,2]:='Agus';
GridMemory.Cells[2,2]:='2/3/2002';
GridMemory.Cells[3,2]:='F';
GridMemory.Cells[1,3]:='Zoe';
GridMemory.Cells[2,3]:='1/7/1939';
GridMemory.Cells[3,3]:='F';
for i:=1 to GridMemory.RowCount-1 do GridMemory.Cells[ 0 , i]:= IntToStr(i);
end;
procedure TMain.FormCreate(Sender: TObject);
var
i:integer;
ExePath: string;
begin
try
for i:=0 to Tabs.PageCount-1 do Tabs.Pages[i].TabVisible:=false;
ListDemos.FullExpand;
ExePath:=ExtractFilePath(ParamStr(0));
for i:=0 to ComponentCount-1 do if (Components[i] is TRichEdit) and (copy(Components[i].Name,1,3)='Txt') then
(Components[i] as TRichEdit).Lines.LoadFromFile( ExePath +'FlDemoSheets\'+ copy(Components[i].Name,4,length(Components[i].Name))+'.rtf');
edSQL.Text:='select * from customer'; //Sometimes it gets deleted if written directly into the designer
FillGridVarArray(GridVarArray1);
FillGridVarArray(GridVarArray2);
FillGridMemory(GridMemory);
edMyImage.Text:= ExePath+'FlexCel.bmp';
except
on e: Exception do
begin
Application.ShowException(e);
ShowMessage('Make sure you have unzipped all the files');
Application.Terminate;
end;
end;//Except
end;
procedure TMain.ListDemosChange(Sender: TObject; Node: TTreeNode);
begin
Tabs.ActivePageIndex:= Node.AbsoluteIndex;
if Tabs.ActivePage.Tag=4 then DemoData.Cust.Open else DemoData.Cust.Close;
end;
procedure TMain.ActionCloseExecute(Sender: TObject);
begin
Close;
end;
procedure TMain.DoReport(const Preview: boolean; const Automatic: boolean; const SendToStream: boolean=false);
var
Dlg: TSaveDialog;
StartTime, EndTime: TDateTime;
begin
StatusBar.SimpleText:='';
//Process Options
if BtnUseNative.Down then
DemoData.SetAdapter(DemoData.XLSAdapter) else
DemoData.SetAdapter(DemoData.OLEAdapter);
DemoData.Protect:= BtnProtect.Down;
//if it's native or HTML, ask the user for a filename
Dlg:=nil;
if BtnUseNative.Down then Dlg:=DemoData.XlsSaveDialog
else if BtnHTML.Down then Dlg:=DemoData.HTMLSaveDialog;
if Automatic then
begin
Dlg:=nil;
DemoData.SetFileName(Directory+'\TestReport'+IntToStr(Tabs.ActivePage.Tag)+'.xls');
if FileExists(Directory+'\TestReport'+IntToStr(Tabs.ActivePage.Tag)+'.xls') then DeleteFile(Directory+'\TestReport'+IntToStr(Tabs.ActivePage.Tag)+'.xls');
end;
if Dlg<>nil then
begin
if not Dlg.Execute then exit;
DemoData.SetFileName(Dlg.FileName);
if FileExists(Dlg.FileName) then DeleteFile(Dlg.FileName);
if SendToStream then DataStream:= TFileStream.Create(Dlg.FileName, fmCreate);
end;
try
Application.ProcessMessages;
DemoData.Cust.Filtered:= Tabs.ActivePage.Tag=6; //So we dont use so many records
if Tabs.ActivePage.Tag=2 then DemoData.FillArrayDemo([GridVarArray1, GridVarArray2]);
if Tabs.ActivePage.Tag=3 then DemoData.MyImageFilename:=edMyImage.Text;
if (Tabs.ActivePage.Tag=6)or(Tabs.ActivePage.Tag=4) then DemoData.Cust.Open;
if Tabs.ActivePage.Tag=4 then DemoData.Cust.Locate('CustNo', LookupCust.KeyValue,[]);
if BtnUseNative.Down then DemoData.RepPivot.Template:='Templates\PivotDemo AutoOpen.xls' else DemoData.RepPivot.Template:='Templates\PivotDemo.xls';
if Tabs.ActivePage.Tag=11 then DemoData.Ds.SQL:= edSQL.Lines;
if Tabs.ActivePage.Tag=13 then DemoData.FillMemTable(GridMemory);
{$IFNDEF Excel97}
DemoData.OLEAdapter.SaveFormatBasic:=[saHtml];
DemoData.GetReport(Tabs.ActivePage.Tag).AutoClose:= BtnHTML.Down and BtnHTML.Enabled;
{$ENDIF}
//Run the report
StartTime:=Now;
DemoData.GetReport(Tabs.ActivePage.Tag).Run;
EndTime:=Now;
StatusBar.SimpleText:=Format('Last Report took: %f seconds', [(EndTime-StartTime)*24*3600]);
finally
if SendToStream then FreeAndNil(DataStream);
end; //finally
if Dlg<>nil then
begin
if Preview then
begin
if DlgReport= nil then DlgReport:=TReport.Create(Self);
DlgReport.WB.Navigate(Dlg.FileName);
try
DlgReport.ShowModal;
finally
FreeAndNil(DlgReport); //only way I've seen to free document
end; //finally
end
else
if DemoData.AutoPrint then
ShellExecute( Handle,'print', PCHAR(Dlg.FileName), NIL,NIL, SW_Hide)
else ShellExecute( Handle,'open', PCHAR(Dlg.FileName), NIL,NIL, SW_SHOW);
end;
end;
procedure TMain.DoImport;
begin
if not DemoData.OpenDialog.Execute then exit;
Application.ProcessMessages;
if BtnUseNative.Down then
DemoData.SetAdapter(DemoData.XLSAdapter) else
DemoData.SetAdapter(DemoData.OLEAdapter);
DemoData.XLSAdapter.TemplateStore:=nil;
try
DemoData.FlexCelImport.OpenFile(DemoData.OpenDialog.FileName);
finally
ActionUseTStore.Execute;
end;//finally
try
if DemoEdit=nil then DemoEdit:=TDemoEdit.Create(Self);
DemoEdit.Caption:=Format(TxtEditing, [DemoData.OpenDialog.FileName]);
DemoEdit.FillData;
DemoEdit.ShowModal;
finally
DemoData.FlexCelImport.CloseFile;
end; //finally
end;
procedure TMain.TestImages(const Fi: TFlexCelImport);
var
PicProps: TImageProperties;
ExePath: string;
begin
ExePath:=ExtractFilePath(ParamStr(0))+'\';
PicProps.Col1:=1;PicProps.Row1:=3;PicProps.Col2:=3;picProps.Row2:=6;
PicProps.dx1:=0;PicProps.dy1:=0;PicProps.dx2:=0;PicProps.dy2:=0;
PicProps.FileName:='C:\Adrian\componentes\flexcel\Demo\FlDemo\flexcel2.jpg';
Fi.AddPicture(DemoData.LoadImageAsJPEG(ExePath+'flexcel.bmp'),xli_Jpeg ,PicProps);
inc(PicProps.Row1,3); inc(PicProps.Row2,3);inc(PicProps.Col1);inc(PicProps.Col2);
Fi.AddPicture(DemoData.LoadImageAsJPEG(ExePath+'flexcel.bmp'),xli_Jpeg ,PicProps);
inc(PicProps.Row1,3); inc(PicProps.Row2,3);inc(PicProps.Col1);inc(PicProps.Col2);
Fi.AddPicture(DemoData.LoadImageAsJPEG(ExePath+'flexcel2.jpg'),xli_Jpeg ,PicProps);
inc(PicProps.Row1,3); inc(PicProps.Row2,3);inc(PicProps.Col1);inc(PicProps.Col2);
Fi.AddPicture(DemoData.LoadImageAsJPEG(ExePath+'flexcel2.jpg'),xli_Jpeg ,PicProps);
inc(PicProps.Row1,3); inc(PicProps.Row2,3);inc(PicProps.Col1);inc(PicProps.Col2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -