You've already forked lazarus-ccr
fpspreadsheet: Add demo fps_export
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6598 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="demo_fpsExport"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<BuildModes Count="2">
|
||||
<Item1 Name="Debug" Default="True"/>
|
||||
<Item2 Name="Release">
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<SmartLinkUnit Value="True"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<StripSymbols Value="True"/>
|
||||
</Debugging>
|
||||
<LinkSmart Value="True"/>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
</Item2>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes Count="1">
|
||||
<Mode0 Name="default"/>
|
||||
</Modes>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="1">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="1">
|
||||
<Unit0>
|
||||
<Filename Value="demo_fpsExport.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="demo_fpsexport"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="..\..\..\source;$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="..\..\..\source\common;..\..\..\source\export"/>
|
||||
<UnitOutputDirectory Value="..\..\lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<SmartLinkUnit Value="True"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf2Set"/>
|
||||
<UseExternalDbgSyms Value="True"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,133 @@
|
||||
program demo_fpsExport;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Classes
|
||||
{ you can add units after this },
|
||||
SysUtils, db, bufdataset,
|
||||
fpspreadsheet, fpsexport;
|
||||
|
||||
type
|
||||
TExportTestData=record
|
||||
id: integer;
|
||||
Name: string;
|
||||
DOB: TDateTime;
|
||||
end;
|
||||
|
||||
var
|
||||
ExportTestData: array[0..5] of TExportTestData;
|
||||
FDataset: TBufDataset;
|
||||
|
||||
procedure InitExportData;
|
||||
begin
|
||||
with ExportTestData[0] do
|
||||
begin
|
||||
id:=1;
|
||||
name:='Elvis Wesley';
|
||||
dob := encodedate(1912,12,31);
|
||||
end;
|
||||
|
||||
with ExportTestData[1] do
|
||||
begin
|
||||
id:=2;
|
||||
name:='Kingsley Dill';
|
||||
dob:=encodedate(1918,11,11);
|
||||
end;
|
||||
|
||||
with ExportTestData[2] do
|
||||
begin
|
||||
id:=3;
|
||||
name:='Joe Snort';
|
||||
dob:=encodedate(1988,8,4);
|
||||
end;
|
||||
|
||||
with ExportTestData[3] do
|
||||
begin
|
||||
id:=4;
|
||||
name:='Hagen Dit';
|
||||
dob:=encodedate(1944,2,24);
|
||||
end;
|
||||
|
||||
with ExportTestData[4] do
|
||||
begin
|
||||
id:=5;
|
||||
name:='Kingsley Snort';
|
||||
dob:=encodedate(1928,11,11);
|
||||
end;
|
||||
|
||||
with ExportTestData[5] do
|
||||
begin
|
||||
id:=6;
|
||||
name:='';
|
||||
dob:=encodedate(2112,4,12);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure CreateDB;
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
FDataset:=TBufDataset.Create(nil);
|
||||
with FDataset.FieldDefs do
|
||||
begin
|
||||
Add('id',ftAutoinc);
|
||||
Add('name',ftString,40);
|
||||
Add('dob',ftDateTime);
|
||||
end;
|
||||
FDataset.CreateDataset;
|
||||
|
||||
for i:=low(ExportTestData) to high(ExportTestData) do
|
||||
begin
|
||||
FDataset.Append;
|
||||
//autoinc field should be filled by bufdataset
|
||||
FDataSet.Fields.FieldByName('name').AsString:=ExportTestData[i].Name;
|
||||
FDataSet.Fields.FieldByName('dob').AsDateTime:=ExportTestData[i].dob;
|
||||
FDataSet.Post;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Cleanup;
|
||||
begin
|
||||
FDataset.Free;
|
||||
end;
|
||||
|
||||
procedure ExportDatabaseToSpreadsheet(AFilename: String);
|
||||
var
|
||||
Exp: TFPSExport;
|
||||
ExpSettings: TFPSExportFormatSettings;
|
||||
begin
|
||||
FDataset.First;
|
||||
Exp := TFPSExport.Create(nil);
|
||||
ExpSettings := TFPSExportFormatSettings.Create(true);
|
||||
try
|
||||
ExpSettings.ExportFormat := efXLS;
|
||||
ExpSettings.HeaderRow := true;
|
||||
Exp.FormatSettings := ExpSettings;
|
||||
Exp.Dataset := FDataset;
|
||||
Exp.FileName := AFileName;
|
||||
Exp.Execute;
|
||||
finally
|
||||
Exp.Free;
|
||||
ExpSettings.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
WriteLn('Preparing test data...');
|
||||
InitExportData;
|
||||
CreateDB;
|
||||
WriteLn('Exporting...');
|
||||
ExportDatabaseToSpreadsheet('temp.xls');
|
||||
WriteLn('Done.');
|
||||
Cleanup;
|
||||
{$IFDEF WINDOWS}
|
||||
WriteLn;
|
||||
WriteLn('Press RETURN to quit.');
|
||||
ReadLn;
|
||||
{$ENDIF}
|
||||
end.
|
||||
|
Reference in New Issue
Block a user