Search in sources :

Example 86 with Workbook

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();
}
Also used : Row(org.apache.poi.ss.usermodel.Row) InternalSheet(org.apache.poi.hssf.model.InternalSheet) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 87 with Workbook

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();
}
Also used : InternalSheet(org.apache.poi.hssf.model.InternalSheet) Sheet(org.apache.poi.ss.usermodel.Sheet) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 88 with Workbook

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();
    }
}
Also used : Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) RecordFormatException(org.apache.poi.hssf.record.RecordFormatException) IOException(java.io.IOException) Test(org.junit.Test)

Example 89 with Workbook

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();
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 90 with Workbook

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();
}
Also used : Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook) Name(org.apache.poi.ss.usermodel.Name) Test(org.junit.Test)

Aggregations

Workbook (org.apache.poi.ss.usermodel.Workbook)319 Sheet (org.apache.poi.ss.usermodel.Sheet)224 Test (org.junit.Test)207 Cell (org.apache.poi.ss.usermodel.Cell)140 Row (org.apache.poi.ss.usermodel.Row)123 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)104 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)95 FileOutputStream (java.io.FileOutputStream)33 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)32 ByteArrayInputStream (java.io.ByteArrayInputStream)30 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)30 XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)27 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)27 File (java.io.File)26 CellStyle (org.apache.poi.ss.usermodel.CellStyle)25 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)24 LangYearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest)23 IOException (java.io.IOException)22 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)18 FileInputStream (java.io.FileInputStream)15