use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestBugs method test55668.
@Test
public void test55668() throws IOException {
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("55668.xls");
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
assertEquals(CellType.FORMULA, cell.getCellTypeEnum());
assertEquals("IF(TRUE,\"\",\"\")", cell.getCellFormula());
assertEquals("", cell.getStringCellValue());
cell.setCellType(CellType.STRING);
assertEquals(CellType.BLANK, cell.getCellTypeEnum());
try {
assertNull(cell.getCellFormula());
fail("Should throw an exception here");
} catch (IllegalStateException e) {
// expected here
}
assertEquals("", cell.getStringCellValue());
wb.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestBugs method bug42016.
@Test
public void bug42016() throws Exception {
Workbook wb = openSample("42016.xls");
Sheet s = wb.getSheetAt(0);
for (int row = 0; row < 7; row++) {
assertEquals("A$1+B$1", s.getRow(row).getCell(2).getCellFormula());
}
wb.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestUnfixedBugs method testFormulaRecordAggregate_1.
@Test
public void testFormulaRecordAggregate_1() throws Exception {
// fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958_1.xls");
try {
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
Sheet sheet = wb.getSheetAt(i);
assertNotNull(wb.getSheet(sheet.getSheetName()));
sheet.groupColumn((short) 4, (short) 5);
sheet.setColumnGroupCollapsed(4, true);
sheet.setColumnGroupCollapsed(4, false);
for (Row row : sheet) {
for (Cell cell : row) {
try {
cell.toString();
} catch (Exception e) {
throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
}
}
}
}
} finally {
wb.close();
}
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestUnfixedBugs method testBug57074.
@Test
public void testBug57074() throws IOException {
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57074.xls");
Sheet sheet = wb.getSheet("Sheet1");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
HSSFColor bgColor = (HSSFColor) cell.getCellStyle().getFillBackgroundColorColor();
String bgColorStr = bgColor.getTriplet()[0] + ", " + bgColor.getTriplet()[1] + ", " + bgColor.getTriplet()[2];
//System.out.println(bgColorStr);
assertEquals("215, 228, 188", bgColorStr);
HSSFColor fontColor = (HSSFColor) cell.getCellStyle().getFillForegroundColorColor();
String fontColorStr = fontColor.getTriplet()[0] + ", " + fontColor.getTriplet()[1] + ", " + fontColor.getTriplet()[2];
//System.out.println(fontColorStr);
assertEquals("0, 128, 128", fontColorStr);
wb.close();
}
use of org.apache.poi.ss.usermodel.Workbook in project poi by apache.
the class TestWorkbook method testBug58085RemoveSheetWithNames.
@Test
public void testBug58085RemoveSheetWithNames() throws Exception {
HSSFWorkbook wb1 = new HSSFWorkbook();
Sheet sheet1 = wb1.createSheet("sheet1");
Sheet sheet2 = wb1.createSheet("sheet2");
Sheet sheet3 = wb1.createSheet("sheet3");
sheet1.createRow(0).createCell((short) 0).setCellValue("val1");
sheet2.createRow(0).createCell((short) 0).setCellValue("val2");
sheet3.createRow(0).createCell((short) 0).setCellValue("val3");
Name namedCell1 = wb1.createName();
namedCell1.setNameName("name1");
String reference1 = "sheet1!$A$1";
namedCell1.setRefersToFormula(reference1);
Name namedCell2 = wb1.createName();
namedCell2.setNameName("name2");
String reference2 = "sheet2!$A$1";
namedCell2.setRefersToFormula(reference2);
Name namedCell3 = wb1.createName();
namedCell3.setNameName("name3");
String reference3 = "sheet3!$A$1";
namedCell3.setRefersToFormula(reference3);
Workbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1);
wb1.close();
Name nameCell = wb2.getName("name1");
assertEquals("sheet1!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name2");
assertEquals("sheet2!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name3");
assertEquals("sheet3!$A$1", nameCell.getRefersToFormula());
wb2.removeSheetAt(wb2.getSheetIndex("sheet1"));
nameCell = wb2.getName("name1");
assertEquals("#REF!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name2");
assertEquals("sheet2!$A$1", nameCell.getRefersToFormula());
nameCell = wb2.getName("name3");
assertEquals("sheet3!$A$1", nameCell.getRefersToFormula());
wb2.close();
}
Aggregations