use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestMirr method testEvaluateInSheet.
public void testEvaluateInSheet() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
row.createCell(0).setCellValue(-7500d);
row.createCell(1).setCellValue(3000d);
row.createCell(2).setCellValue(5000d);
row.createCell(3).setCellValue(1200d);
row.createCell(4).setCellValue(4000d);
row.createCell(5).setCellValue(0.05d);
row.createCell(6).setCellValue(0.08d);
HSSFCell cell = row.createCell(7);
cell.setCellFormula("MIRR(A1:E1, F1, G1)");
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
fe.clearAllCachedResultValues();
fe.evaluateFormulaCellEnum(cell);
double res = cell.getNumericCellValue();
assertEquals(0.18736225093, res, 0.00000001);
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestErrPtg method testReading.
/**
* Tests reading a file containing this ptg.
*/
public void testReading() {
HSSFWorkbook workbook = loadWorkbook("ErrPtg.xls");
HSSFCell cell = workbook.getSheetAt(0).getRow(3).getCell(0);
assertEquals("Wrong cell value", 4.0, cell.getNumericCellValue(), 0.0);
assertEquals("Wrong cell formula", "ERROR.TYPE(#REF!)", cell.getCellFormula());
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestIntersectionPtg method testReading.
/**
* Tests reading a file containing this ptg.
*/
public void testReading() {
HSSFWorkbook workbook = loadWorkbook("IntersectionPtg.xls");
HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2);
assertEquals("Wrong cell value", 5.0, cell.getNumericCellValue(), 0.0);
assertEquals("Wrong cell formula", "SUM(A1:B2 B2:C3)", cell.getCellFormula());
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestUnionPtg method testReading.
/**
* Tests reading a file containing this ptg.
*/
public void testReading() {
HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls");
HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell(2);
assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0);
assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula());
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project poi by apache.
the class TestEvaluationCache method testBlankCellChangedToValueCell_bug46053.
/**
* Make sure that when blank cells are changed to value/formula cells, any dependent formulas
* have their cached results cleared.
*/
public void testBlankCellChangedToValueCell_bug46053() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cellA1 = row.createCell(0);
HSSFCell cellB1 = row.createCell(1);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
cellA1.setCellFormula("B1+2.2");
cellB1.setCellValue(1.5);
fe.notifyUpdateCell(cellA1);
fe.notifyUpdateCell(cellB1);
CellValue cv;
cv = fe.evaluate(cellA1);
assertEquals(3.7, cv.getNumberValue(), 0.0);
cellB1.setCellType(CellType.BLANK);
fe.notifyUpdateCell(cellB1);
// B1 was used to evaluate A1
cv = fe.evaluate(cellA1);
assertEquals(2.2, cv.getNumberValue(), 0.0);
// changing B1, so A1 cached result should be cleared
cellB1.setCellValue(0.4);
fe.notifyUpdateCell(cellB1);
cv = fe.evaluate(cellA1);
if (cv.getNumberValue() == 2.2) {
// looks like left-over cached result from before change to B1
throw new AssertionFailedError("Identified bug 46053");
}
assertEquals(2.6, cv.getNumberValue(), 0.0);
}
Aggregations