\r
package org.apache.poi.xssf.usermodel;\r
\r
+import static org.junit.Assert.assertEquals;\r
+\r
import java.io.IOException;\r
import java.nio.charset.Charset;\r
import java.util.Calendar;\r
import org.apache.poi.ss.usermodel.Cell;\r
import org.apache.poi.ss.usermodel.DataFormatter;\r
import org.apache.poi.ss.usermodel.DateUtil;\r
+import org.apache.poi.ss.usermodel.FormulaError;\r
import org.apache.poi.ss.usermodel.RichTextString;\r
import org.apache.poi.ss.usermodel.Row;\r
import org.apache.poi.ss.usermodel.Sheet;\r
assertEquals(2, strBack.getIndexOfFormattingRun(1));\r
assertEquals(4, strBack.getIndexOfFormattingRun(2));\r
}\r
+\r
+ @Test\r
+ public void testBug56655() {\r
+ XSSFWorkbook wb = new XSSFWorkbook();\r
+ Sheet sheet = wb.createSheet();\r
+ \r
+ setCellFormula(sheet, 0, 0, "#VALUE!");\r
+ setCellFormula(sheet, 0, 1, "SUMIFS(A:A,A:A,#VALUE!)");\r
+\r
+ XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);\r
+\r
+ assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0,0).getCachedFormulaResultType());\r
+ assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,0).getErrorCellValue());\r
+ assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0,1).getCachedFormulaResultType());\r
+ assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0,1).getErrorCellValue());\r
+ }\r
+\r
+ @Test\r
+ public void testBug56655a() {\r
+ XSSFWorkbook wb = new XSSFWorkbook();\r
+ Sheet sheet = wb.createSheet();\r
+ \r
+ setCellFormula(sheet, 0, 0, "B1*C1");\r
+ sheet.getRow(0).createCell(1).setCellValue("A");\r
+ setCellFormula(sheet, 1, 0, "B1*C1");\r
+ sheet.getRow(1).createCell(1).setCellValue("A");\r
+ setCellFormula(sheet, 0, 3, "SUMIFS(A:A,A:A,A2)");\r
+\r
+ XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);\r
+\r
+ assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0, 0).getCachedFormulaResultType());\r
+ assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 0).getErrorCellValue());\r
+ assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 1, 0).getCachedFormulaResultType());\r
+ assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 1, 0).getErrorCellValue());\r
+ assertEquals(XSSFCell.CELL_TYPE_ERROR, getCell(sheet, 0, 3).getCachedFormulaResultType());\r
+ assertEquals(FormulaError.VALUE.getCode(), getCell(sheet, 0, 3).getErrorCellValue());\r
+ }\r
+\r
+ /**\r
+ * @param row 0-based\r
+ * @param column 0-based\r
+ */\r
+ void setCellFormula(Sheet sheet, int row, int column, String formula) {\r
+ Row r = sheet.getRow(row);\r
+ if (r == null) {\r
+ r = sheet.createRow(row);\r
+ }\r
+ Cell cell = r.getCell(column);\r
+ if (cell == null) {\r
+ cell = r.createCell(column);\r
+ }\r
+ cell.setCellType(XSSFCell.CELL_TYPE_FORMULA);\r
+ cell.setCellFormula(formula);\r
+ }\r
+\r
+ /**\r
+ * @param rowNo 0-based\r
+ * @param column 0-based\r
+ */\r
+ Cell getCell(Sheet sheet, int rowNo, int column) {\r
+ return sheet.getRow(rowNo).getCell(column);\r
+ }\r
}\r