Search in sources :

Example 1 with CTPivotCache

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache in project poi by apache.

the class TestXSSFWorkbook method testAddPivotCache.

@Test
public void testAddPivotCache() throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook();
    try {
        CTWorkbook ctWb = wb.getCTWorkbook();
        CTPivotCache pivotCache = wb.addPivotCache("0");
        //Ensures that pivotCaches is initiated
        assertTrue(ctWb.isSetPivotCaches());
        assertSame(pivotCache, ctWb.getPivotCaches().getPivotCacheArray(0));
        assertEquals("0", pivotCache.getId());
    } finally {
        wb.close();
    }
}
Also used : CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook) CTPivotCache(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache) Test(org.junit.Test)

Example 2 with CTPivotCache

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache in project poi by apache.

the class XSSFWorkbook method addPivotCache.

/**
     * Add pivotCache to the workbook
     */
@Beta
protected CTPivotCache addPivotCache(String rId) {
    CTWorkbook ctWorkbook = getCTWorkbook();
    CTPivotCaches caches;
    if (ctWorkbook.isSetPivotCaches()) {
        caches = ctWorkbook.getPivotCaches();
    } else {
        caches = ctWorkbook.addNewPivotCaches();
    }
    CTPivotCache cache = caches.addNewPivotCache();
    int tableId = getPivotTables().size() + 1;
    cache.setCacheId(tableId);
    cache.setId(rId);
    if (pivotCaches == null) {
        pivotCaches = new ArrayList<CTPivotCache>();
    }
    pivotCaches.add(cache);
    return cache;
}
Also used : CTPivotCaches(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCaches) CTWorkbook(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook) CTPivotCache(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache) Beta(org.apache.poi.util.Beta)

Aggregations

CTPivotCache (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache)2 CTWorkbook (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook)2 Beta (org.apache.poi.util.Beta)1 Test (org.junit.Test)1 CTPivotCaches (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCaches)1