Search in sources :

Example 11 with AreaReference

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

the class TestRangeEval method confirm.

private static void confirm(String refA, String refB, String expectedAreaRef) {
    ValueEval[] args = { createRefEval(refA), createRefEval(refB) };
    @SuppressWarnings("deprecation") AreaReference ar = new AreaReference(expectedAreaRef);
    ValueEval result = EvalInstances.Range.evaluate(args, 0, (short) 0);
    assertTrue(result instanceof AreaEval);
    AreaEval ae = (AreaEval) result;
    assertEquals(ar.getFirstCell().getRow(), ae.getFirstRow());
    assertEquals(ar.getLastCell().getRow(), ae.getLastRow());
    assertEquals(ar.getFirstCell().getCol(), ae.getFirstColumn());
    assertEquals(ar.getLastCell().getCol(), ae.getLastColumn());
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference)

Example 12 with AreaReference

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

the class XSSFPivotTable method createSourceReferences.

/**
     * Creates cacheSource and workSheetSource for pivot table and sets the source reference as well assets the location of the pivot table
     * @param position Position for pivot table in sheet
     * @param sourceSheet Sheet where the source will be collected from
     * @param refConfig  an configurator that knows how to configure pivot table references
     */
@Beta
protected void createSourceReferences(CellReference position, Sheet sourceSheet, PivotTableReferenceConfigurator refConfig) {
    //Get cell one to the right and one down from position, add both to AreaReference and set pivot table location.
    AreaReference destination = new AreaReference(position, new CellReference(position.getRow() + 1, position.getCol() + 1));
    CTLocation location;
    if (pivotTableDefinition.getLocation() == null) {
        location = pivotTableDefinition.addNewLocation();
        location.setFirstDataCol(1);
        location.setFirstDataRow(1);
        location.setFirstHeaderRow(1);
    } else {
        location = pivotTableDefinition.getLocation();
    }
    location.setRef(destination.formatAsString());
    pivotTableDefinition.setLocation(location);
    //Set source for the pivot table
    CTPivotCacheDefinition cacheDef = getPivotCacheDefinition().getCTPivotCacheDefinition();
    CTCacheSource cacheSource = cacheDef.addNewCacheSource();
    cacheSource.setType(STSourceType.WORKSHEET);
    CTWorksheetSource worksheetSource = cacheSource.addNewWorksheetSource();
    worksheetSource.setSheet(sourceSheet.getSheetName());
    setDataSheet(sourceSheet);
    refConfig.configureReference(worksheetSource);
    if (worksheetSource.getName() == null && worksheetSource.getRef() == null)
        throw new IllegalArgumentException("Pivot table source area reference or name must be specified.");
}
Also used : CTLocation(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLocation) CTPivotCacheDefinition(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCacheDefinition) AreaReference(org.apache.poi.ss.util.AreaReference) CTCacheSource(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheSource) CellReference(org.apache.poi.ss.util.CellReference) CTWorksheetSource(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource) Beta(org.apache.poi.util.Beta)

Example 13 with AreaReference

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

the class TestXSSFBugs method bug51963.

/**
     * Sheet names with a , in them
     */
@Test
public void bug51963() throws IOException {
    XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("51963.xlsx");
    Sheet sheet = wb.getSheetAt(0);
    assertEquals("Abc,1", sheet.getSheetName());
    Name name = wb.getName("Intekon.ProdCodes");
    assertEquals("'Abc,1'!$A$1:$A$2", name.getRefersToFormula());
    AreaReference ref = new AreaReference(name.getRefersToFormula(), SpreadsheetVersion.EXCEL2007);
    assertEquals(0, ref.getFirstCell().getRow());
    assertEquals(0, ref.getFirstCell().getCol());
    assertEquals(1, ref.getLastCell().getRow());
    assertEquals(0, ref.getLastCell().getCol());
    wb.close();
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTDefinedName(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName) Test(org.junit.Test)

Example 14 with AreaReference

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

the class TestXSSFSheet method testCreateTwoPivotTablesInTwoSheets.

@Test
public void testCreateTwoPivotTablesInTwoSheets() 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);
    assertNotNull(wb);
    XSSFSheet sheet2 = wb.createSheet();
    XSSFPivotTable pivotTable2 = sheet2.createPivotTable(new AreaReference("A1:B2", SpreadsheetVersion.EXCEL2007), new CellReference("H5"), 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 15 with AreaReference

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

the class TestXSSFSheet method testCreatePivotTable.

@Test
public void testCreatePivotTable() 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);
    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)

Aggregations

AreaReference (org.apache.poi.ss.util.AreaReference)32 CellReference (org.apache.poi.ss.util.CellReference)19 Test (org.junit.Test)10 Beta (org.apache.poi.util.Beta)7 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)6 Cell (org.apache.poi.ss.usermodel.Cell)4 Row (org.apache.poi.ss.usermodel.Row)4 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 FileOutputStream (java.io.FileOutputStream)2 MemFuncPtg (org.apache.poi.ss.formula.ptg.MemFuncPtg)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 CTPivotField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField)2 CTPivotFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields)2 CTWorksheetSource (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource)2 InputStream (java.io.InputStream)1 QName (javax.xml.namespace.QName)1 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)1 NameRecord (org.apache.poi.hssf.record.NameRecord)1 HSSFEvaluationWorkbook (org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)1