You've already forked lazarus-ccr
fpspreadsheet: Add demo for conditional formatting
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7493 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -0,0 +1,63 @@
|
||||
<?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_conditional_formatting"/>
|
||||
<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_conditional_formatting.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="demo_conditional_formatting"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,48 @@
|
||||
program demo_conditional_formatting;
|
||||
|
||||
uses
|
||||
sysUtils,
|
||||
fpsTypes, fpsUtils, fpspreadsheet, xlsxooxml, fpsconditionalformat;
|
||||
|
||||
var
|
||||
wb: TsWorkbook;
|
||||
sh: TsWorksheet;
|
||||
fmt: TsCellFormat;
|
||||
fmtIdx: Integer;
|
||||
font: TsFont;
|
||||
|
||||
begin
|
||||
wb := TsWorkbook.Create;
|
||||
try
|
||||
sh := wb.AddWorksheet('test');
|
||||
sh.WriteNumber(0, 0, 1.0);
|
||||
sh.WriteNumber(1, 0, 2.0);
|
||||
sh.WriteNumber(2, 0, 3.0);
|
||||
sh.WriteNumber(3, 0, 4.0);
|
||||
sh.WriteNumber(4, 0, 5.0);
|
||||
|
||||
// Prepare the format record
|
||||
InitFormatRecord(fmt);
|
||||
// ... set the background color
|
||||
fmt.SetBackgroundColor(scYellow);
|
||||
// ... set the borders
|
||||
fmt.SetBorders([cbNorth, cbEast, cbWest], scBlack, lsThin);
|
||||
fmt.SetBorders([cbSouth], scRed, lsThick);
|
||||
// ... set the font (bold) ---- NOT SUPPORTED AT THE MOMENT...
|
||||
font := wb.CloneFont(0);
|
||||
font.Style := [fssBold, fssItalic];
|
||||
font.Color := scRed;
|
||||
fmt.SetFont(wb.AddFont(font));
|
||||
// Add format record to format list
|
||||
fmtIdx := wb.AddCellFormat(fmt);
|
||||
|
||||
// Use the format as conditional format of A1:A6 when cells are equal to 3.
|
||||
sh.WriteConditionalCellFormat(Range(0, 0, 5, 0), cfcEqual, 3.0, fmtIdx);
|
||||
|
||||
wb.WriteToFile('test.xlsx', true);
|
||||
finally
|
||||
wb.Free;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user