Skip to content

Commit

Permalink
Bug 58571: Add test which shows a workaround
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923053 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Jan 11, 2025
1 parent ae9355d commit 147c034
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,30 @@ private void checkFormulaValue(Workbook wb, Cell cell, String formula, String ex
CellValue value = evaluateFormulaInCell(wb, cell, formula);
assertEquals(expectedValue, value.getStringValue());
}

@Test
public void testFormula_58571() throws IOException {
try (Workbook wb = new HSSFWorkbook()) {
FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();

Sheet sheet = wb.createSheet("test");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
// it seems the two double-quotes are replaced with one double-quote when parsing the function
// this does not work: cell.setCellFormula("TEXT(B1, \"h\"\"h\"\" m\"\"m\"\"\")");
cell.setCellFormula("TEXT(B1, \"h\"\"\"\"h\"\"\"\" m\"\"\"\"m\"\"\"\"\")");

Cell cellValue = row.createCell(1);
cellValue.setCellValue(0.0104166666666666);

CellValue value = eval.evaluate(cell);
assertEquals(CellType.STRING, value.getCellType());
assertEquals("0h 15m", value.getStringValue());

cellValue.setCellValue(1.123);
value = eval.evaluate(cell);
assertEquals(CellType.STRING, value.getCellType());
assertEquals("0h 15m", value.getStringValue());
}
}
}

0 comments on commit 147c034

Please sign in to comment.