use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class MergedCells method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(1);
HSSFCell cell = row.createCell(1);
cell.setCellValue("This is a test of merging");
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParser method testUnderscore.
/** bug 35027, underscore in sheet name */
@Test
public void testUnderscore() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet("Cash_Flow");
HSSFSheet sheet = wb.createSheet("Test");
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
cell = row.createCell(0);
cell.setCellFormula("Cash_Flow!A1");
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParser method testNamesWithUnderscore.
/** bug 49725, defined names with underscore */
@Test
public void testNamesWithUnderscore() throws IOException {
//or new XSSFWorkbook();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("NamesWithUnderscore");
HSSFName nm;
nm = wb.createName();
nm.setNameName("DA6_LEO_WBS_Number");
nm.setRefersToFormula("33");
nm = wb.createName();
nm.setNameName("DA6_LEO_WBS_Name");
nm.setRefersToFormula("33");
nm = wb.createName();
nm.setNameName("A1_");
nm.setRefersToFormula("22");
nm = wb.createName();
nm.setNameName("_A1");
nm.setRefersToFormula("11");
nm = wb.createName();
nm.setNameName("A_1");
nm.setRefersToFormula("44");
nm = wb.createName();
nm.setNameName("A_1_");
nm.setRefersToFormula("44");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellFormula("DA6_LEO_WBS_Number*2");
assertEquals("DA6_LEO_WBS_Number*2", cell.getCellFormula());
cell.setCellFormula("(A1_*_A1+A_1)/A_1_");
assertEquals("(A1_*_A1+A_1)/A_1_", cell.getCellFormula());
cell.setCellFormula("INDEX(DA6_LEO_WBS_Name,MATCH($A3,DA6_LEO_WBS_Number,0))");
assertEquals("INDEX(DA6_LEO_WBS_Name,MATCH($A3,DA6_LEO_WBS_Number,0))", cell.getCellFormula());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParser method testSetFormulaWithRowBeyond32768_Bug44539.
@Test
public void testSetFormulaWithRowBeyond32768_Bug44539() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellFormula("SUM(A32769:A32770)");
if ("SUM(A-32767:A-32766)".equals(cell.getCellFormula())) {
fail("Identified bug 44539");
}
assertEquals("SUM(A32769:A32770)", cell.getCellFormula());
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project poi by apache.
the class TestFormulaParserEval method testEvaluateFormulaWithRowBeyond32768_Bug44539.
public void testEvaluateFormulaWithRowBeyond32768_Bug44539() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
wb.setSheetName(0, "Sheet1");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);
cell.setCellFormula("SUM(A32769:A32770)");
// put some values in the cells to make the evaluation more interesting
sheet.createRow(32768).createCell(0).setCellValue(31);
sheet.createRow(32769).createCell(0).setCellValue(11);
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
CellValue result;
try {
result = fe.evaluate(cell);
} catch (FormulaParseException e) {
if (!e.getMessage().equals("Found reference to named range \"A\", but that named range wasn't defined!")) {
throw new AssertionFailedError("Identifed bug 44539");
}
throw e;
}
assertEquals(CellType.NUMERIC, result.getCellTypeEnum());
assertEquals(42.0, result.getNumberValue(), 0.0);
}
Aggregations