Refresh and Calculate Pivot Table having Calculated Items
Refresh and Calculate Pivot Table having Calculated Items
The following sample code loads the source excel file which contains a pivot table having three calculated items such as “add”, “div”, “div2”. We first change the value of cell D2 to 20 and then refresh and calculate pivot table using Aspose.Cells for Node.js via C++ APIs and save the workbook in PDF format. The results in the output PDF shows that Aspose.Cells for Node.js via C++ refreshed and calculated the pivot table having calculated items successfully. You can verify it using Microsoft Excel by manually putting the value 20 in cell D2 and then refreshing the pivot table via Alt+F5 shortcut key or clicking the pivot table Refresh button.
const AsposeCells = require("aspose.cells.node"); | |
//For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
//The path to the documents directory. | |
var dataDir = RunExamples.GetDataDir("."); | |
//Load source excel file containing a pivot table having calculated items | |
var wb = new AsposeCells.Workbook(dataDir + "sample.xlsx"); | |
//Access first worksheet | |
var sheet = wb.getWorksheets().get(0); | |
//Change the value of cell D2 | |
sheet.getCells().get("D2").putValue(20); | |
//Refresh and calculate all the pivot tables inside this sheet | |
sheet.refreshPivotTables(); | |
//Save the workbook in output pdf | |
wb.save(dataDir + "RefreshAndCalculateItems_out.pdf", AsposeCells.SaveFormat.Pdf); |