Pivot Tablo İşleme

Olası Kullanım Senaryoları

Yeni pivot tablo oluşturmanın yanı sıra, yeni ve mevcut pivot tablolarının üzerinde çalışabilirsiniz. Pivot tablosunun kaynak aralığındaki verileri değiştirebilir ve ardından pivot tablosunu yenileyebilir ve hesaplayabilir ve pivot tablosu hücrelerinin yeni değerlerine ulaşabilirsiniz. Pivot tablosunun kaynak aralığındaki değerleri değiştirdikten sonra, lütfen yenilemek için PivotTable.RefreshData() ve PivotTable.CalculateData() yöntemlerini kullanın.

Pivot Tablo İşleme

Aşağıdaki örnek kod, örnek excel dosyasını yükler ve ilk çalışma sayfasındaki mevcut pivot tablosuna erişir. Pivot tablosunun kaynak aralığındaki B3 hücresinin değerini değiştirir ve ardından pivot tablosunu yeniler. Pivot tablosunu yenilemeden önce, pivot tablosu hücresi H8’in değerine erişir, bu değer 15’tir ve pivot tablosunu yeniledikten sonra, değeri 6’ya değişir. Lütfen bu kod ile oluşturulmuş çıktı excel dosyasını ve örnek excel dosyası üzerinde örnek kodun etkisini gösteren ekran görüntüsünü kontrol edin. Ayrıca aşağıda, pivot tablosunun yenilenmesinden önce ve sonra pivot tablosu hücresinin H8 değerini gösteren konsol çıktısına da bakınız.

todo:image_alt_text

Örnek Kod

Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Source directory path
U16String dirPath(u"..\\Data\\PivotTables\\");
//Output directory path
U16String outPath(u"..\\Data\\Output\\");
//Path of input excel file
U16String sampleManipulatePivotTable = dirPath + u"sampleManipulatePivotTable.xlsx";
//Path of output excel file
U16String outputManipulatePivotTable = outPath + u"outputManipulatePivotTable.xlsx";
//Load the sample excel file
Workbook wb(sampleManipulatePivotTable);
//Access first worksheet
Worksheet ws = wb.GetWorksheets().Get(0);
//Change value of cell B3 which is inside the source data of pivot table
ws.GetCells().Get(u"B3").PutValue(u"Cup");
//Get the value of cell H8 before refreshing pivot table
U16String val = ws.GetCells().Get(u"H8").GetStringValue();
std::cout << "Before refreshing Pivot Table value of cell H8: " << val.ToUtf8() << std::endl;
//Access pivot table, refresh and calculate it
PivotTable pt = ws.GetPivotTables().Get(0);
pt.RefreshData();
pt.CalculateData();
//Get the value of cell H8 after refreshing pivot table
val = ws.GetCells().Get(u"H8").GetStringValue();
std::cout << "After refreshing Pivot Table value of cell H8: " << val.ToUtf8() << std::endl;
//Save the output excel file
wb.Save(outputManipulatePivotTable);
Aspose::Cells::Cleanup();

Konsol Çıktısı

Aşağıda, sağlanan örnek excel dosyası ile birlikte yürütüldüğünde yukarıdaki örnek kodun konsol çıktısı bulunmaktadır.

 Before refreshing Pivot Table value of cell H8: 15

After refreshing Pivot Table value of cell H8: 6