You've already forked lazarus-ccr
+ fpspreadsheet: add spreadsheet dataset export visual package laz_fpspreadsheetexport_visual.lpk
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3646 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -11,7 +11,7 @@ unit fpsexport;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, db, fpsallformats, fpspreadsheet, fpdbexport;
|
Classes, SysUtils, db, fpsallformats, fpspreadsheet, fpsstrings, fpdbexport;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
|
|
||||||
@@ -24,10 +24,10 @@ Type
|
|||||||
property DestField : TField read FDestField;
|
property DestField : TField read FDestField;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFPSExportFormatSettings }
|
|
||||||
|
|
||||||
TExportFormat = (efXLS {BIFF8},efXLSX,efODS,efWikiTable);
|
TExportFormat = (efXLS {BIFF8},efXLSX,efODS,efWikiTable);
|
||||||
|
|
||||||
|
{ TFPSExportFormatSettings }
|
||||||
|
{@@ Specific export settings that apply to spreadsheet export}
|
||||||
TFPSExportFormatSettings = class(TExportFormatSettings)
|
TFPSExportFormatSettings = class(TExportFormatSettings)
|
||||||
private
|
private
|
||||||
FExportFormat: TExportFormat;
|
FExportFormat: TExportFormat;
|
||||||
@@ -36,9 +36,10 @@ Type
|
|||||||
procedure Assign(Source : TPersistent); override;
|
procedure Assign(Source : TPersistent); override;
|
||||||
procedure InitSettings; override;
|
procedure InitSettings; override;
|
||||||
published
|
published
|
||||||
// File format for the export
|
{@@ File format for the export }
|
||||||
property ExportFormat: TExportFormat read FExportFormat write FExportFormat;
|
property ExportFormat: TExportFormat read FExportFormat write FExportFormat;
|
||||||
// Write the field list to the first row of the spreadsheet or not
|
{@@ Flag that determines whethe to write the field list to the first
|
||||||
|
row of the spreadsheet }
|
||||||
property HeaderRow: boolean read FHeaderRow write FHeaderRow default false;
|
property HeaderRow: boolean read FHeaderRow write FHeaderRow default false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -63,30 +64,38 @@ Type
|
|||||||
property FileName: String read FFileName write FFileName;
|
property FileName: String read FFileName write FFileName;
|
||||||
property Workbook: TsWorkbook read FSpreadsheet;
|
property Workbook: TsWorkbook read FSpreadsheet;
|
||||||
public
|
public
|
||||||
|
{@@ Settings for the export. Note: a lot of generic settings are preent
|
||||||
|
that are not relevant for this export, e.g. decimal point settings }
|
||||||
property FormatSettings: TFPSExportFormatSettings read GetSettings write SetSettings;
|
property FormatSettings: TFPSExportFormatSettings read GetSettings write SetSettings;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TFPSExport }
|
||||||
|
{@@ Export class allowing dataset export to spreadsheet(like) file }
|
||||||
TFPSExport = Class(TCustomFPSExport)
|
TFPSExport = Class(TCustomFPSExport)
|
||||||
published
|
published
|
||||||
|
{@@ Destination filename }
|
||||||
property FileName;
|
property FileName;
|
||||||
|
{@@ Source dataset }
|
||||||
property Dataset;
|
property Dataset;
|
||||||
|
{@@ Fields to be exported }
|
||||||
property ExportFields;
|
property ExportFields;
|
||||||
|
{@@ Export starting from current record or beginning. }
|
||||||
property FromCurrent;
|
property FromCurrent;
|
||||||
|
{@@ Flag indicating whether to return to current dataset position after export }
|
||||||
property RestorePosition;
|
property RestorePosition;
|
||||||
property FormatSettings;
|
property FormatSettings;
|
||||||
|
{@@ Procedure to run when exporting a row }
|
||||||
property OnExportRow;
|
property OnExportRow;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{@@ Register export format with fpsdbexport so it can be dynamically used }
|
||||||
procedure RegisterFPSExportFormat;
|
procedure RegisterFPSExportFormat;
|
||||||
|
{@@ Remove registration. Opposite to RegisterFPSExportFormat }
|
||||||
procedure UnRegisterFPSExportFormat;
|
procedure UnRegisterFPSExportFormat;
|
||||||
|
|
||||||
const
|
const
|
||||||
SFPSExport = 'xls';
|
SFPSExport = 'xls';
|
||||||
SPFSExtension = '.xls'; //todo: add others?
|
SPFSExtension = '.xls'; //Add others? Doesn't seem to fit other dxport units
|
||||||
|
|
||||||
resourcestring
|
|
||||||
SFPSDescription = 'Spreadsheet files';
|
|
||||||
SFPSFileMustExist = 'Empty file names are not allowed.';
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@@ -118,15 +127,12 @@ procedure TCustomFPSExport.DoBeforeExecute;
|
|||||||
begin
|
begin
|
||||||
Inherited;
|
Inherited;
|
||||||
if FFileName='' then
|
if FFileName='' then
|
||||||
Raise EDataExporter.Create(SFPSFileMustExist);
|
Raise EDataExporter.Create(rsExportFileIsRequired);
|
||||||
FSpreadsheet:=TsWorkbook.Create;
|
FSpreadsheet:=TsWorkbook.Create;
|
||||||
// For extra performance. Note that virtual mode is not an option
|
// For extra performance. Note that virtual mode is not an option
|
||||||
// due to the data export determining flow of the program.
|
// due to the data export determining flow of the program.
|
||||||
FSpreadsheet.Options:=FSpreadsheet.Options+[boBufStream];
|
FSpreadsheet.Options:=FSpreadsheet.Options+[boBufStream];
|
||||||
FSheet:=FSpreadsheet.AddWorksheet('1');
|
FSheet:=FSpreadsheet.AddWorksheet('1');
|
||||||
// todo: look into restoring position after done
|
|
||||||
if not(Dataset.IsUniDirectional) then
|
|
||||||
Dataset.First; // needed to export all items
|
|
||||||
FRow:=0;
|
FRow:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -205,7 +211,7 @@ end;
|
|||||||
|
|
||||||
procedure RegisterFPSExportFormat;
|
procedure RegisterFPSExportFormat;
|
||||||
begin
|
begin
|
||||||
ExportFormats.RegisterExportFormat(SFPSExport,SFPSDescription,SPFSExtension,TFPSExport);
|
ExportFormats.RegisterExportFormat(SFPSExport,rsFPSExportDescription,SPFSExtension,TFPSExport);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure UnRegisterFPSExportFormat;
|
procedure UnRegisterFPSExportFormat;
|
||||||
|
34
components/fpspreadsheet/fpsexportreg.pas
Normal file
34
components/fpspreadsheet/fpsexportreg.pas
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
Registration for fpsexport into the Lazarus component palette
|
||||||
|
This requires package lazdbexport for property editors etc
|
||||||
|
}
|
||||||
|
unit fpsexportreg;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, LazarusPackageIntf, lresources, fpdataexporter;
|
||||||
|
|
||||||
|
Procedure Register;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
//todo: add component graphic
|
||||||
|
//{$R fpsexportimg.res}
|
||||||
|
|
||||||
|
uses
|
||||||
|
fpsexport;
|
||||||
|
|
||||||
|
Procedure Register;
|
||||||
|
|
||||||
|
begin
|
||||||
|
RegisterComponents('Data Export',[TFPSExport]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterPackage('Data Export', @Register );
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@@ -10,6 +10,8 @@ unit fpsStrings;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
resourcestring
|
resourcestring
|
||||||
|
rsExportFileIsRequired = 'Export file name is required';
|
||||||
|
rsFPSExportDescription = 'Spreadsheet file';
|
||||||
rsUnsupportedReadFormat = 'Tried to read a spreadsheet using an unsupported format';
|
rsUnsupportedReadFormat = 'Tried to read a spreadsheet using an unsupported format';
|
||||||
rsUnsupportedWriteFormat = 'Tried to write a spreadsheet using an unsupported format';
|
rsUnsupportedWriteFormat = 'Tried to write a spreadsheet using an unsupported format';
|
||||||
rsNoValidSpreadsheetFile = '"%s" is not a valid spreadsheet file';
|
rsNoValidSpreadsheetFile = '"%s" is not a valid spreadsheet file';
|
||||||
|
62
components/fpspreadsheet/laz_fpspreadsheetexport_visual.lpk
Normal file
62
components/fpspreadsheet/laz_fpspreadsheetexport_visual.lpk
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<Package Version="4">
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<Name Value="laz_fpspreadsheetexport_visual"/>
|
||||||
|
<Author Value="Reinier Olislagers and others"/>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<PathDelim Value="\"/>
|
||||||
|
<SearchPaths>
|
||||||
|
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
|
<UseAnsiStrings Value="False"/>
|
||||||
|
</SyntaxOptions>
|
||||||
|
</Parsing>
|
||||||
|
<Other>
|
||||||
|
<CustomOptions Value="$(IDEBuildOptions)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Description Value="laz_fpspreadsheetexport_visual is a visual component for exporting datasets to spreadsheet (.xls/.xlsx/.ods/wikitable formats).
|
||||||
|
|
||||||
|
It provides a graphical export component on the Data Export tab."/>
|
||||||
|
<License Value="LGPL with static linking exception. This is the same license as is used in the LCL (Lazarus Component Library)."/>
|
||||||
|
<Version Major="1" Minor="2"/>
|
||||||
|
<Files Count="2">
|
||||||
|
<Item1>
|
||||||
|
<Filename Value="fpsexport.pas"/>
|
||||||
|
<UnitName Value="fpsexport"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Filename Value="fpsexportreg.pas"/>
|
||||||
|
<HasRegisterProc Value="True"/>
|
||||||
|
<UnitName Value="fpsexportreg"/>
|
||||||
|
</Item2>
|
||||||
|
</Files>
|
||||||
|
<Type Value="RunAndDesignTime"/>
|
||||||
|
<RequiredPkgs Count="4">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="lazdbexport"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<PackageName Value="laz_fpspreadsheet"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<PackageName Value="LCL"/>
|
||||||
|
</Item3>
|
||||||
|
<Item4>
|
||||||
|
<PackageName Value="FCL"/>
|
||||||
|
<MinVersion Major="1" Valid="True"/>
|
||||||
|
</Item4>
|
||||||
|
</RequiredPkgs>
|
||||||
|
<UsageOptions>
|
||||||
|
<UnitPath Value="$(PkgOutDir)"/>
|
||||||
|
</UsageOptions>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<IgnoreBinaries Value="False"/>
|
||||||
|
</PublishOptions>
|
||||||
|
</Package>
|
||||||
|
</CONFIG>
|
@@ -121,7 +121,6 @@ var
|
|||||||
TempFile: string;
|
TempFile: string;
|
||||||
TheDate: TDateTime;
|
TheDate: TDateTime;
|
||||||
begin
|
begin
|
||||||
FDataset.First;
|
|
||||||
Exp := TFPSExport.Create(nil);
|
Exp := TFPSExport.Create(nil);
|
||||||
ExpSettings := TFPSExportFormatSettings.Create(true);
|
ExpSettings := TFPSExportFormatSettings.Create(true);
|
||||||
try
|
try
|
||||||
@@ -129,6 +128,7 @@ begin
|
|||||||
ExpSettings.HeaderRow := true;
|
ExpSettings.HeaderRow := true;
|
||||||
Exp.FormatSettings := ExpSettings;
|
Exp.FormatSettings := ExpSettings;
|
||||||
Exp.Dataset:=FDataset;
|
Exp.Dataset:=FDataset;
|
||||||
|
Exp.FromCurrent:=false; //export from beginning
|
||||||
TempFile := NewTempFile;
|
TempFile := NewTempFile;
|
||||||
Exp.FileName := TempFile;
|
Exp.FileName := TempFile;
|
||||||
CheckEquals(length(ExportTestData),Exp.Execute,'Number of exported records');
|
CheckEquals(length(ExportTestData),Exp.Execute,'Number of exported records');
|
||||||
|
Reference in New Issue
Block a user