Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ConditionalFormattingExpressionRule(String expression, boolean stopIfTrue
public void write(Writer w) throws IOException {
w
.append("<cfRule type=\"").append(TYPE).append("\" priority=\"").append(priority).append("\" stopIfTrue=\"").append(stopIfTrue ? "1" : "0").append("\" dxfId=\"").append(dxfId).append("\">")
.append("<formula>").append(expression).append("</formula>")
.append("<formula>").appendEscaped(expression).append("</formula>")
.append("</cfRule>");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,21 @@ void hasValidCellConditionalFormatting() throws Exception {
assertTrue(cellRange.formatAsString().equals("A1"));
}

@Test
void conditionalFormattingExpressionIsEscaped() throws Exception {
String formula = "IF(A1<5,A1&\"x\",\"\")";
byte[] data = writeWorkbook(wb -> {
Worksheet ws = wb.newWorksheet("Worksheet 1");
ws.style(0, 0).fillColor("FF8800").set(new ConditionalFormattingExpressionRule(formula, true));
});

try (XSSFWorkbook workbook = new XSSFWorkbook(new ByteArrayInputStream(data))) {
XSSFConditionalFormattingRule rule = workbook.getSheetAt(0)
.getSheetConditionalFormatting().getConditionalFormattingAt(0).getRule(0);
assertEquals(formula, rule.getFormula1());
}
}

@Test
void hasValidRangeConditionalFormatting() throws Exception {
byte[] data = writeWorkbook(wb -> {
Expand Down