Yenileme ve Hesaplanmış Öğeleri Olan Özet Tabloyu Yenileme

Hesaplanmış öğeleri olan özet tabloyu yenileme ve hesaplama

Aşağıdaki örnek kod, içerisinde “add”, “div” ve “div2” gibi üç hesaplanmış öğe bulunan bir pivot tablosunu içeren kaynak excel dosyasını yükler. İlk olarak D2 hücresinin değerini 20 olarak değiştiririz ve sonra Aspose.Cells API’lerini kullanarak pivot tablosunu yeniler ve hesaplar, ardından sonucu PDF formatında kaydeder. Çıktı PDF’indeki sonuçlar, Aspose.Cells’in başarılı bir şekilde hesaplanmış öğeleri içeren pivot tablosunu yenilediğini ve hesaplama yaptığını göstermektedir. Bu durumu Microsoft Excel’i kullanarak manuel olarak D2 hücresine 20 değerini girerek ve sonra pivot tablosunu Alt+F5 kısayol tuşunu kullanarak veya pivot tablosu Yenile düğmesine tıklayarak doğrulayabilirsiniz.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Load source excel file containing a pivot table having calculated items
Workbook wb = new Workbook(dataDir + "sample.xlsx");
// Access first worksheet
Worksheet sheet = wb.Worksheets[0];
// Change the value of cell D2
sheet.Cells["D2"].PutValue(20);
// Refresh and calculate all the pivot tables inside this sheet
foreach (PivotTable pt in sheet.PivotTables)
{
pt.RefreshData();
pt.CalculateData();
}
// Save the workbook in output pdf
wb.Save(dataDir + "RefreshAndCalculateItems_out.pdf", SaveFormat.Pdf);