Search in sources :

Example 96 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class TestXSSFTable method getEndCellReference.

@Test
public void getEndCellReference() throws IOException {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx");
    XSSFTable table = wb.getTable("\\_Prime.1");
    assertEquals(new CellReference("C7"), table.getEndCellReference());
    wb.close();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CellReference(org.apache.poi.ss.util.CellReference) Test(org.junit.Test)

Example 97 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class TestXSSFTable method getStartCellReference.

@Test
public void getStartCellReference() throws IOException {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx");
    XSSFTable table = wb.getTable("\\_Prime.1");
    assertEquals(new CellReference("A1"), table.getStartCellReference());
    wb.close();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CellReference(org.apache.poi.ss.util.CellReference) Test(org.junit.Test)

Example 98 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class TestXSSFTable method getCellReferences.

@Test
public void getCellReferences() {
    // make sure that cached start and end cell references
    // can be synchronized with the underlying CTTable
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();
    XSSFTable table = sh.createTable();
    CTTable ctTable = table.getCTTable();
    ctTable.setRef("B2:E8");
    assertEquals(new CellReference("B2"), table.getStartCellReference());
    assertEquals(new CellReference("E8"), table.getEndCellReference());
    // At this point start and end cell reference are cached
    // and may not follow changes to the underlying CTTable
    ctTable.setRef("C1:M3");
    assertEquals(new CellReference("B2"), table.getStartCellReference());
    assertEquals(new CellReference("E8"), table.getEndCellReference());
    // Force a synchronization between CTTable and XSSFTable
    // start and end cell references
    table.updateReferences();
    assertEquals(new CellReference("C1"), table.getStartCellReference());
    assertEquals(new CellReference("M3"), table.getEndCellReference());
}
Also used : CTTable(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CellReference(org.apache.poi.ss.util.CellReference) Test(org.junit.Test)

Example 99 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class TestXSSFSheet method testCreateTwoPivotTablesInOneSheet.

@Test
public void testCreateTwoPivotTablesInOneSheet() throws IOException {
    XSSFWorkbook wb = setupSheet();
    XSSFSheet sheet = wb.getSheetAt(0);
    assertNotNull(wb);
    assertNotNull(sheet);
    XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:B2", SpreadsheetVersion.EXCEL2007), new CellReference("H5"));
    assertNotNull(pivotTable);
    assertTrue(wb.getPivotTables().size() > 0);
    XSSFPivotTable pivotTable2 = sheet.createPivotTable(new AreaReference("A1:B2", SpreadsheetVersion.EXCEL2007), new CellReference("L5"), sheet);
    assertNotNull(pivotTable2);
    assertTrue(wb.getPivotTables().size() > 1);
    wb.close();
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CellReference(org.apache.poi.ss.util.CellReference) Test(org.junit.Test)

Example 100 with CellReference

use of org.apache.poi.ss.util.CellReference in project poi by apache.

the class MemoryUsage method mixedSpreadsheet.

/**
     * Generate a spreadsheet until OutOfMemoryError
     * <p>
     *  cells in even columns are numbers, cells in odd columns are strings
     * </p>
     *
     * @param wb        the workbook to write to
     * @param numCols   the number of columns in a row
     */
public static void mixedSpreadsheet(Workbook wb, int numCols) {
    System.out.println("Testing " + wb.getClass().getName());
    printMemoryUsage("before");
    int i = 0, cnt = 0;
    try {
        Sheet sh = wb.createSheet();
        for (i = 0; ; i++) {
            Row row = sh.createRow(i);
            for (int j = 0; j < numCols; j++) {
                Cell cell = row.createCell(j);
                if (j % 2 == 0)
                    cell.setCellValue(j);
                else
                    cell.setCellValue(new CellReference(j, i).formatAsString());
                cnt++;
            }
        }
    } catch (OutOfMemoryError er) {
        System.out.println("Failed at row=" + i + ", objects : " + cnt);
    } catch (final Exception e) {
        System.out.println("Unable to reach an OutOfMemoryError");
        System.out.println(e.getClass().getName() + ": " + e.getMessage());
    }
    printMemoryUsage("after");
}
Also used : Row(org.apache.poi.ss.usermodel.Row) CellReference(org.apache.poi.ss.util.CellReference) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

CellReference (org.apache.poi.ss.util.CellReference)125 Test (org.junit.Test)52 Cell (org.apache.poi.ss.usermodel.Cell)28 Row (org.apache.poi.ss.usermodel.Row)27 AreaReference (org.apache.poi.ss.util.AreaReference)20 Sheet (org.apache.poi.ss.usermodel.Sheet)18 Workbook (org.apache.poi.ss.usermodel.Workbook)14 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)14 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)13 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)12 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)11 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)8 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)8 CellStyle (org.apache.poi.ss.usermodel.CellStyle)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)5 RichTextString (org.apache.poi.ss.usermodel.RichTextString)5 FileOutputStream (java.io.FileOutputStream)4 OutputStream (java.io.OutputStream)4