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();
}
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();
}
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());
}
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();
}
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");
}
Aggregations