Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jlangch committed Sep 3, 2024
1 parent 39f2fcc commit 4b2ccea
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,12 @@ public void copyCellStyle(
}

public void conditionalBackgroundColor(
final String condRule, // "ISBLANK(A1)"
final String condRegion, // "A1:B1"
final String bgColorHtml // "#CC636A"
final String condRule, // "ISBLANK(A1)"
final String bgColorHtml, // "#CC636A"
final int regionFirstRow,
final int regionLastRow,
final int regionFirstCol,
final int regionLastCol
) {
// Create a conditional formatting rule for blank cells
final SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
Expand All @@ -331,7 +334,9 @@ public void conditionalBackgroundColor(
fill.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

// Define the range of cells to apply the rule
final CellRangeAddress[] regions = { CellRangeAddress.valueOf(condRegion) };
final CellRangeAddress[] regions = { new CellRangeAddress(
regionFirstRow, regionLastRow,
regionFirstCol, regionLastCol) };

// Apply the conditional formatting rule to the sheet
sheetCF.addConditionalFormatting(regions, rule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,20 @@ public void copyCellStyle(
}

public void conditionalBackgroundColor(
final String condRule, // "ISBLANK(A1)"
final String condRegion, // "A1:B1"
final String bgColorHtml // "#CC636A"
final String condRule, // "ISBLANK(A1)"
final String bgColorHtml, // "#CC636A"
final int regionFirstRow1,
final int regionLastRow1,
final int regionFirstCol1,
final int regionLastCol1
) {
sheet.conditionalBackgroundColor(condRule, condRegion, bgColorHtml);
sheet.conditionalBackgroundColor(
condRule,
bgColorHtml,
regionFirstRow1-1,
regionLastRow1-1,
regionFirstCol1-1,
regionLastCol1-1);
}

public void addTextDataValidation(
Expand Down
23 changes: 18 additions & 5 deletions src/main/resources/com/github/jlangch/venice/excel.venice
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,10 @@

(defn
^{ :arglists '(
"(conditional-bg-color sheet rule region bg-color-html)")
"(conditional-bg-color sheet
rule bg-color-html
region-first-row region-last-row
region-first-col region-last-col)")
:doc "Conditional background color"
:examples '(
"""
Expand All @@ -829,7 +832,7 @@
sheet (excel/add-sheet wbook "Sheet 1")]
(excel/write-values sheet 1 1 "John" "Doe" 28)
(excel/write-values sheet 2 1 "Sue" "Ford" 26)
(excel/conditional-bg-color sheet "ISBLANK(B1)" "B1:B99" "#CC636A")
(excel/conditional-bg-color sheet "ISBLANK(B1)" "#CC636A" 1 2 2 2)
(excel/auto-size-columns sheet)
(excel/write->file wbook "sample.xlsx")))
""" )
Expand All @@ -840,11 +843,21 @@
"excel/auto-size-columns", "excel/auto-size-column",
"excel/row-height") }

conditional-bg-color [sheet rule region bg-color-html]
conditional-bg-color [sheet
rule bg-color-html
region-first-row region-last-row
region-first-col region-last-col]

{ :pre [(instance-of? :ExcelSheetFacade sheet)] }
{ :pre [(instance-of? :ExcelSheetFacade sheet)
(long? region-first-row) (pos? region-first-row)
(long? region-last-row) (pos? region-last-row)
(long? region-first-col) (pos? region-first-col)
(long? region-last-col) (pos? region-last-col)] }

(. sheet :conditionalBackgroundColor rule region bg-color-html))
(. sheet :conditionalBackgroundColor rule
bg-color-html
region-first-row region-last-row
region-first-col region-last-col))


(defn
Expand Down

0 comments on commit 4b2ccea

Please sign in to comment.