fpspreadsheet: Add examples for writing and reading files with defined names
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9402 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
0d6a27eff3
commit
6a7f67931b
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="demo_read_definednames"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<RequiredPackages>
|
||||
<Item>
|
||||
<PackageName Value="laz_fpspreadsheet"/>
|
||||
</Item>
|
||||
</RequiredPackages>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="demo_read_definednames.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="demo_read_definednames"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf3"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,54 @@
|
||||
program demo_read_definednames;
|
||||
{.$DEFINE ODS}
|
||||
uses
|
||||
fpspreadsheet, fpsTypes, fpsClasses, fpsUtils, fpsAllFormats;
|
||||
var
|
||||
wb: TsWorkbook;
|
||||
ws: TsWorksheet;
|
||||
cell: PCell;
|
||||
i: Integer;
|
||||
fn: String;
|
||||
begin
|
||||
{$IFDEF ODS}
|
||||
fn := 'test_defnames.ods';
|
||||
{$ELSE}
|
||||
fn := 'test_defnames.xlsx';
|
||||
{$ENDIF}
|
||||
|
||||
wb := TsWorkbook.Create;
|
||||
try
|
||||
wb.Options := [boAutoCalc, boReadFormulas];
|
||||
|
||||
wb.ReadFromFile(fn);
|
||||
ws := wb.GetFirstWorksheet;
|
||||
|
||||
WriteLn('FILE: ', fn, LineEnding);
|
||||
|
||||
WriteLn('DEFINED NAMES');
|
||||
for i := 0 to wb.DefinedNames.Count-1 do
|
||||
WriteLn(wb.DefinedNames[i].Name, ' --> ', wb.DefinedNames[i].RangeAsString(wb));
|
||||
|
||||
WriteLn;
|
||||
WriteLn('CELLS');
|
||||
for cell in ws.Cells do
|
||||
begin
|
||||
Write(GetCellString(cell^.Row, cell^.Col), ' --> ', ws.ReadAsText(cell));
|
||||
if HasFormula(cell) then
|
||||
Write(' (formula: ', ws.GetFormula(cell)^.Text, ')');
|
||||
WriteLn;
|
||||
end;
|
||||
|
||||
finally
|
||||
wb.Free;
|
||||
end;
|
||||
|
||||
if ParamCount = 0 then
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
WriteLn('Press [ENTER] to quit...');
|
||||
ReadLn;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="demo_write_definednames"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<RequiredPackages>
|
||||
<Item>
|
||||
<PackageName Value="laz_fpspreadsheet"/>
|
||||
</Item>
|
||||
</RequiredPackages>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="demo_write_definednames.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="demo_write_definednames"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf3"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,31 @@
|
||||
program demo_write_definednames;
|
||||
uses
|
||||
fpspreadsheet, fpsTypes, fpsUtils, fpsClasses, fpsAllFormats;
|
||||
var
|
||||
wb: TsWorkbook;
|
||||
ws: TsWorksheet;
|
||||
wsIdx: Integer;
|
||||
i: Integer;
|
||||
begin
|
||||
wb := TsWorkbook.Create;
|
||||
try
|
||||
wb.Options := [boAutoCalc];
|
||||
ws := wb.AddWorksheet('Test');
|
||||
wsIdx := wb.GetWorksheetIndex(ws);
|
||||
|
||||
wb.DefinedNames.Add('distance', wsIdx, 1, 2);
|
||||
ws.WriteText(1, 1, 'distance'); ws.WriteNumber(1, 2, 120); ws.WriteFormula(1, 3, '=distance');
|
||||
|
||||
ws.WriteText(2, 1, 'time'); ws.WriteNumber(2, 2, 60);
|
||||
wb.DefinedNames.Add('time', wsIdx, 2, 2);
|
||||
|
||||
wb.DefinedNames.Add('speed', wsIdx, 3, 2);
|
||||
ws.WriteText(3, 1, 'speed'); ws.WriteFormula(3, 2, '=distance/time');
|
||||
|
||||
wb.WriteToFile('test_defnames.xlsx', true);
|
||||
wb.WriteToFile('test_defnames.ods', true);
|
||||
finally
|
||||
wb.Free;
|
||||
end;
|
||||
end.
|
||||
|
@ -68,6 +68,11 @@
|
||||
<Mode Name="Release"/>
|
||||
</BuildModes>
|
||||
</Target>
|
||||
<Target FileName="defined_names\demo_write_definednames.lpi">
|
||||
<BuildModes>
|
||||
<Mode Name="Default"/>
|
||||
</BuildModes>
|
||||
</Target>
|
||||
<Target FileName="searching\demo_search.lpi">
|
||||
<BuildModes>
|
||||
<Mode Name="Default"/>
|
||||
|
@ -42,6 +42,9 @@ This folder contains various demo applications:
|
||||
can be registered in fpspreadsheet for usage in rpn formulas. The example
|
||||
covers some financial functions.
|
||||
|
||||
- defined_names: shows how "defined names" (named cells) can be used in
|
||||
FPSpreadsheet. Also in formulas.
|
||||
|
||||
- virtual_mode/demo_virtualmode_writing: demonstrates how the virtual mode
|
||||
of the workbook can be used to create huge spreadsheet files.
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
cell_formats\demo_write_formatting -quit
|
||||
colors\demo_write_colors -quit
|
||||
conditional_formatting\demo_conditional_formatting -quit
|
||||
defined_names\demo_write_definednames -quit
|
||||
expression_parser\demo_expression_parser -quit
|
||||
frozen_rowscols\demo_frozen_rows_cols -quit
|
||||
header_footer_images\demo_write_headerfooter_images -quit
|
||||
|
Loading…
Reference in New Issue
Block a user