From e1fc35b13ab7ed228b76c4e29a4b37047183aa9d Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 25 Jun 2020 17:23:36 +0000 Subject: [PATCH] fpspreadsheet: Add demo for conditional formatting git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7493 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../demo_conditional_formatting.lpi | 63 +++++++++++++++++++ .../demo_conditional_formatting.pas | 48 ++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.lpi create mode 100644 components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas diff --git a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.lpi b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.lpi new file mode 100644 index 000000000..abe7843b3 --- /dev/null +++ b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.lpi @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + <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> diff --git a/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas new file mode 100644 index 000000000..264135838 --- /dev/null +++ b/components/fpspreadsheet/examples/other/conditional_formatting/demo_conditional_formatting.pas @@ -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. +