use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParser method testRanges.
@Test
public void testRanges() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Cash_Flow");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
String formula;
cell.setCellFormula("A1.A2");
formula = cell.getCellFormula();
assertEquals("A1:A2", formula);
cell.setCellFormula("A1..A2");
formula = cell.getCellFormula();
assertEquals("A1:A2", formula);
cell.setCellFormula("A1...A2");
formula = cell.getCellFormula();
assertEquals("A1:A2", formula);
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParser method testBackSlashInNames.
/** Named ranges with backslashes, e.g. 'POI\\2009' */
@Test
public void testBackSlashInNames() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFName name = wb.createName();
name.setNameName("POI\\2009");
name.setRefersToFormula("Sheet1!$A$1");
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow(0);
HSSFCell cell_C1 = row.createCell(2);
cell_C1.setCellFormula("POI\\2009");
assertEquals("POI\\2009", cell_C1.getCellFormula());
HSSFCell cell_D1 = row.createCell(2);
cell_D1.setCellFormula("NOT(POI\\2009=\"3.5-final\")");
assertEquals("NOT(POI\\2009=\"3.5-final\")", cell_D1.getCellFormula());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParser method testWorksheetReferences.
@Test
public void testWorksheetReferences() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("NoQuotesNeeded");
wb.createSheet("Quotes Needed Here &#$@");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
cell = row.createCell(0);
cell.setCellFormula("NoQuotesNeeded!A1");
cell = row.createCell(1);
cell.setCellFormula("'Quotes Needed Here &#$@'!A1");
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestSheet method testSetMargins_bug45717.
/**
* In 3.1, setting margins between creating first row and first cell caused an exception.
*/
@Test
public void testSetMargins_bug45717() throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Vorschauliste");
HSSFRow row = sheet.createRow(0);
sheet.setMargin(HSSFSheet.LeftMargin, 0.3);
try {
row.createCell(0);
} catch (IllegalStateException e) {
if (e.getMessage().equals("Cannot create value records before row records exist")) {
fail("Identified bug 45717");
}
throw e;
} finally {
workbook.close();
}
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestRangeEval method testRangeUsingOffsetFunc_bug46948.
public void testRangeUsingOffsetFunc_bug46948() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFRow row = wb.createSheet("Sheet1").createRow(0);
HSSFCell cellA1 = row.createCell(0);
HSSFCell cellB1 = row.createCell(1);
// C1
row.createCell(2).setCellValue(5.0);
// D1
row.createCell(3).setCellValue(7.0);
// E1
row.createCell(4).setCellValue(9.0);
cellA1.setCellFormula("SUM(C1:OFFSET(C1,0,B1))");
// range will be C1:D1
cellB1.setCellValue(1.0);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue cv;
try {
cv = fe.evaluate(cellA1);
} catch (IllegalArgumentException e) {
if (e.getMessage().equals("Unexpected ref arg class (org.apache.poi.ss.formula.LazyAreaEval)")) {
throw new AssertionFailedError("Identified bug 46948");
}
throw e;
}
assertEquals(12.0, cv.getNumberValue(), 0.0);
// range will be C1:E1
cellB1.setCellValue(2.0);
fe.notifyUpdateCell(cellB1);
cv = fe.evaluate(cellA1);
assertEquals(21.0, cv.getNumberValue(), 0.0);
// range will be C1:C1
cellB1.setCellValue(0.0);
fe.notifyUpdateCell(cellB1);
cv = fe.evaluate(cellA1);
assertEquals(5.0, cv.getNumberValue(), 0.0);
}
Aggregations