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
|
||||
|
||||
uses
|
||||
Classes, SysUtils, db, fpsallformats, fpspreadsheet, fpdbexport;
|
||||
Classes, SysUtils, db, fpsallformats, fpspreadsheet, fpsstrings, fpdbexport;
|
||||
|
||||
Type
|
||||
|
||||
@ -24,10 +24,10 @@ Type
|
||||
property DestField : TField read FDestField;
|
||||
end;
|
||||
|
||||
{ TFPSExportFormatSettings }
|
||||
|
||||
TExportFormat = (efXLS {BIFF8},efXLSX,efODS,efWikiTable);
|
||||
|
||||
|
||||
{ TFPSExportFormatSettings }
|
||||
{@@ Specific export settings that apply to spreadsheet export}
|
||||
TFPSExportFormatSettings = class(TExportFormatSettings)
|
||||
private
|
||||
FExportFormat: TExportFormat;
|
||||
@ -36,9 +36,10 @@ Type
|
||||
procedure Assign(Source : TPersistent); override;
|
||||
procedure InitSettings; override;
|
||||
published
|
||||
// File format for the export
|
||||
{@@ File format for the export }
|
||||
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;
|
||||
end;
|
||||
|
||||
@ -63,31 +64,39 @@ Type
|
||||
property FileName: String read FFileName write FFileName;
|
||||
property Workbook: TsWorkbook read FSpreadsheet;
|
||||
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;
|
||||
end;
|
||||
|
||||
{ TFPSExport }
|
||||
{@@ Export class allowing dataset export to spreadsheet(like) file }
|
||||
TFPSExport = Class(TCustomFPSExport)
|
||||
published
|
||||
{@@ Destination filename }
|
||||
property FileName;
|
||||
{@@ Source dataset }
|
||||
property Dataset;
|
||||
{@@ Fields to be exported }
|
||||
property ExportFields;
|
||||
{@@ Export starting from current record or beginning. }
|
||||
property FromCurrent;
|
||||
{@@ Flag indicating whether to return to current dataset position after export }
|
||||
property RestorePosition;
|
||||
property FormatSettings;
|
||||
{@@ Procedure to run when exporting a row }
|
||||
property OnExportRow;
|
||||
end;
|
||||
|
||||
|
||||
{@@ Register export format with fpsdbexport so it can be dynamically used }
|
||||
procedure RegisterFPSExportFormat;
|
||||
{@@ Remove registration. Opposite to RegisterFPSExportFormat }
|
||||
procedure UnRegisterFPSExportFormat;
|
||||
|
||||
const
|
||||
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
|
||||
|
||||
|
||||
@ -118,15 +127,12 @@ procedure TCustomFPSExport.DoBeforeExecute;
|
||||
begin
|
||||
Inherited;
|
||||
if FFileName='' then
|
||||
Raise EDataExporter.Create(SFPSFileMustExist);
|
||||
Raise EDataExporter.Create(rsExportFileIsRequired);
|
||||
FSpreadsheet:=TsWorkbook.Create;
|
||||
// For extra performance. Note that virtual mode is not an option
|
||||
// due to the data export determining flow of the program.
|
||||
FSpreadsheet.Options:=FSpreadsheet.Options+[boBufStream];
|
||||
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;
|
||||
end;
|
||||
|
||||
@ -205,7 +211,7 @@ end;
|
||||
|
||||
procedure RegisterFPSExportFormat;
|
||||
begin
|
||||
ExportFormats.RegisterExportFormat(SFPSExport,SFPSDescription,SPFSExtension,TFPSExport);
|
||||
ExportFormats.RegisterExportFormat(SFPSExport,rsFPSExportDescription,SPFSExtension,TFPSExport);
|
||||
end;
|
||||
|
||||
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
|
||||
|
||||
resourcestring
|
||||
rsExportFileIsRequired = 'Export file name is required';
|
||||
rsFPSExportDescription = 'Spreadsheet file';
|
||||
rsUnsupportedReadFormat = 'Tried to read a spreadsheet using an unsupported format';
|
||||
rsUnsupportedWriteFormat = 'Tried to write a spreadsheet using an unsupported format';
|
||||
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;
|
||||
TheDate: TDateTime;
|
||||
begin
|
||||
FDataset.First;
|
||||
Exp := TFPSExport.Create(nil);
|
||||
ExpSettings := TFPSExportFormatSettings.Create(true);
|
||||
try
|
||||
@ -129,6 +128,7 @@ begin
|
||||
ExpSettings.HeaderRow := true;
|
||||
Exp.FormatSettings := ExpSettings;
|
||||
Exp.Dataset:=FDataset;
|
||||
Exp.FromCurrent:=false; //export from beginning
|
||||
TempFile := NewTempFile;
|
||||
Exp.FileName := TempFile;
|
||||
CheckEquals(length(ExportTestData),Exp.Execute,'Number of exported records');
|
||||
|
Reference in New Issue
Block a user