Search in sources :

Example 81 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class TestUnfixedBugs method testFormulaRecordAggregate.

@Test
public void testFormulaRecordAggregate() throws Exception {
    // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
    Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958.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 82 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class TestHSSFWorkbook method testRewriteFileBug58480.

@Test
public void testRewriteFileBug58480() throws IOException {
    final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
    try {
        // create new workbook
        {
            final Workbook workbook = new HSSFWorkbook();
            final Sheet sheet = workbook.createSheet("foo");
            final Row row = sheet.createRow(1);
            row.createCell(1).setCellValue("bar");
            writeAndCloseWorkbook(workbook, file);
        }
        // edit the workbook
        {
            NPOIFSFileSystem fs = new NPOIFSFileSystem(file, false);
            try {
                DirectoryNode root = fs.getRoot();
                final Workbook workbook = new HSSFWorkbook(root, true);
                final Sheet sheet = workbook.getSheet("foo");
                sheet.getRow(1).createCell(2).setCellValue("baz");
                writeAndCloseWorkbook(workbook, file);
            } finally {
                fs.close();
            }
        }
    } finally {
        assertTrue(file.exists());
        assertTrue(file.delete());
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) Row(org.apache.poi.ss.usermodel.Row) TempFile(org.apache.poi.util.TempFile) File(java.io.File) 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) BaseTestWorkbook(org.apache.poi.ss.usermodel.BaseTestWorkbook) Test(org.junit.Test)

Example 83 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class TestCellFormat method testApplyFormatHasThreePartsFirstTwoHaveCondition.

@Test
public void testApplyFormatHasThreePartsFirstTwoHaveCondition() throws Exception {
    // Create a workbook, row and cell to test with
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet();
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    CellFormat cf = CellFormat.getInstance("[>=100]0.00;[>=10]0.000;0.0000");
    cell.setCellValue(100);
    assertEquals("100.00", cf.apply(cell).text);
    cell.setCellValue(10);
    assertEquals("10.000", cf.apply(cell).text);
    cell.setCellValue(0);
    assertEquals("0.0000", cf.apply(cell).text);
    cell.setCellValue(-10);
    assertEquals("-10.0000", cf.apply(cell).text);
    cell.setCellValue("abc");
    assertEquals("abc", cf.apply(cell).text);
    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) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 84 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class TestCellFormat method testApplyFormatHasFourPartsSecondHasCondition.

@Test
public void testApplyFormatHasFourPartsSecondHasCondition() throws Exception {
    // Create a workbook, row and cell to test with
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet();
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    CellFormat cf = CellFormat.getInstance("0.00;[>=100]0.000;0.0000;~~@~~");
    cell.setCellValue(100);
    assertEquals("100.00", cf.apply(cell).text);
    cell.setCellValue(10);
    assertEquals("10.00", cf.apply(cell).text);
    cell.setCellValue(0.123456789012345);
    assertEquals("0.12", cf.apply(cell).text);
    cell.setCellValue(0);
    assertEquals("0.0000", cf.apply(cell).text);
    cell.setCellValue(-10);
    assertEquals("-10.0000", cf.apply(cell).text);
    cell.setCellValue("abc");
    assertEquals("~~abc~~", cf.apply(cell).text);
    cell.setCellValue(true);
    assertEquals("~~TRUE~~", cf.apply(cell).text);
    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) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 85 with Row

use of org.apache.poi.ss.usermodel.Row in project poi by apache.

the class TestCellFormat method testApplyFormatHasThreePartsFirstTwoHaveConditionThirdIsGeneral.

@Test
public void testApplyFormatHasThreePartsFirstTwoHaveConditionThirdIsGeneral() throws Exception {
    // Create a workbook, row and cell to test with
    Workbook wb = new HSSFWorkbook();
    Sheet sheet = wb.createSheet();
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    CellFormat cf = CellFormat.getInstance("[>=100]0.00;[>=10]0.000;General");
    cell.setCellValue(100);
    assertEquals("100.00", cf.apply(cell).text);
    cell.setCellValue(10);
    assertEquals("10.000", cf.apply(cell).text);
    cell.setCellValue(0);
    assertEquals("0", cf.apply(cell).text);
    cell.setCellValue(-10);
    assertEquals("-10", cf.apply(cell).text);
    cell.setCellValue("abc");
    assertEquals("abc", cf.apply(cell).text);
    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) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Aggregations

Row (org.apache.poi.ss.usermodel.Row)316 Cell (org.apache.poi.ss.usermodel.Cell)230 Sheet (org.apache.poi.ss.usermodel.Sheet)179 Workbook (org.apache.poi.ss.usermodel.Workbook)125 Test (org.junit.Test)116 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)55 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)44 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)35 CellStyle (org.apache.poi.ss.usermodel.CellStyle)27 CellReference (org.apache.poi.ss.util.CellReference)22 ArrayList (java.util.ArrayList)21 FileOutputStream (java.io.FileOutputStream)20 IOException (java.io.IOException)17 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)17 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)17 HashMap (java.util.HashMap)16 RichTextString (org.apache.poi.ss.usermodel.RichTextString)16 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)16 List (java.util.List)14 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)14