[]
An IPivotCache stores the source data used by one or more PivotTable reports. You can create a cache from a range or table through IPivotCaches.create(Object), inspect its source data and refresh settings, and create a PivotTable from the cache by calling createPivotTable(IRange) or createPivotTable(IRange,String).
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Product", "Category", "Amount"},
{"Carrots", "Vegetables", 1200},
{"Broccoli", "Vegetables", 850},
{"Bananas", "Fruit", 640}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
pivotCache.createPivotTable(worksheet.getRange("E1"));
createPivotTable(IRange TableDestination) createPivotTable(IRange TableDestination,
String TableName) IPivotTable report from this pivot cache at the specified destination.intgetIndex()intbooleanvoidrefresh()voidsetRefreshOnFileOpen(boolean value) voidsetSourceData(IRange value)
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Name", "Score"},
{"Alice", 100},
{"Bob", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
int index = pivotCache.getIndex();
This value reflects the number of source records currently stored in the cache.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Region", "Sales"},
{"East", 100},
{"West", 200},
{"East", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
int recordCount = pivotCache.getRecordCount();
getRefreshLocalDateTime() instead.This method is obsolete. Use getRefreshLocalDateTime() instead.
Use this method to retrieve the refresh timestamp recorded for the cache after calling refresh().
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Name", "Score"},
{"Alice", 100},
{"Bob", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
pivotCache.refresh();
LocalDateTime refreshTime = pivotCache.getRefreshLocalDateTime();
Use this method to retrieve the refresh user recorded in the cache metadata.
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Name", "Score"},
{"Alice", 100},
{"Bob", 200}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
pivotCache.refresh();
String refreshName = pivotCache.getRefreshName();
Returns the IRange currently used by this PivotTable cache as its source data. Use setSourceData(IRange) to change the source range.
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Product", "Category", "Amount"},
{"Apple", "Fruit", 100},
{"Pear", "Fruit", 200},
{"Carrot", "Vegetable", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IRange sourceData = pivotCache.getSourceData();
Use this method to change the IRange that provides the source data for this pivot cache.
worksheet.getRange("A1:B3").setValue(new Object[][] {
{"Product", "Amount"},
{"Apple", 100},
{"Orange", 200}
});
worksheet.getRange("D1:E3").setValue(new Object[][] {
{"Product", "Amount"},
{"Banana", 150},
{"Pear", 180}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
pivotCache.setSourceData(worksheet.getRange("D1:E3"));
value - The range that contains the source data for the PivotTable report.The specified destination identifies the upper-left cell of the PivotTable report. The destination range must be on a worksheet in the workbook that contains this PivotCache object.
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Product", "Category", "Amount"},
{"Apple", "Fruit", 100},
{"Pear", "Fruit", 200},
{"Carrot", "Vegetable", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IPivotTable pivotTable = pivotCache.createPivotTable(worksheet.getRange("E1"));
TableDestination - The cell in the upper-left corner of the PivotTable report's destination range. The destination range must be on a worksheet in the workbook that contains this PivotCache object; null is not supported.IPivotTable object.IPivotTable report from this pivot cache at the specified destination.The pivot table is created on the worksheet that contains TableDestination. TableDestination specifies the upper-left cell of the destination area where the resulting pivot table will be placed.
worksheet.getRange("A1:C4").setValue(new Object[][] {
{"Product", "Region", "Amount"},
{"Apple", "East", 100},
{"Apple", "West", 120},
{"Pear", "East", 90}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:C4"));
IPivotTable pivotTable = pivotCache.createPivotTable(worksheet.getRange("E1"), "SalesSummary");
pivotTable.getPivotFields().get("Product").setOrientation(PivotFieldOrientation.RowField);
TableDestination - The upper-left cell of the destination range where the new pivot table report will be placed. This value must not be null.TableName - The name of the new pivot table report. This value can be null.IPivotTable.Use this method after changing the cache source range to reload the cached records used by PivotTable reports that are based on this IPivotCache.
worksheet.getRange("A1:B3").setValue(new Object[][] {{"Region", "Sales"}, {"East", 120}, {"West", 150}});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B3"));
pivotCache.createPivotTable(worksheet.getRange("D1"));
worksheet.getRange("B3").setValue(180);
pivotCache.refresh();
IllegalStateException - if the source sheet of the PivotCache cannot be found.The default value is false.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Vegetable", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
pivotCache.setRefreshOnFileOpen(true);
boolean refreshOnFileOpen = pivotCache.getRefreshOnFileOpen();
true if the PivotTable cache is automatically updated each time the workbook is opened; otherwise, false.The default value is false.
worksheet.getRange("A1:B4").setValue(new Object[][] {
{"Category", "Amount"},
{"Fruit", 100},
{"Vegetable", 200},
{"Fruit", 150}
});
IPivotCache pivotCache = workbook.getPivotCaches().create(worksheet.getRange("A1:B4"));
pivotCache.setRefreshOnFileOpen(true);
value - true if the PivotTable cache is automatically updated each time the workbook is opened; otherwise, false.
getRefreshLocalDateTime()instead.