Pivot Tablodaki Pivot Alanlarını Gruplandırma
Contents
[
Hide
]
Olası Kullanım Senaryoları
Microsoft Excel, pivot tablonun pivot alanlarını gruplandırmanıza olanak tanır. Bir pivot alanıyla ilgili çok miktarda veri olduğunda, bunları bölümler halinde gruplandırmak genellikle yararlıdır. Aspose.Cells ayrıca bu özelliği kullanarakPivotTable.setManualGroupField() yöntem.
Pivot Tablodaki Pivot Alanlarını Gruplandırma
Aşağıdaki örnek kod,örnek excel dosyasıkullanarak ilk pivot alanında gruplandırma gerçekleştirir.PivotTable.setManualGroupField() yöntem. Daha sonra pivot tablonun verilerini yeniler ve hesaplar ve çalışma kitabınıçıktı excel dosyası. Ekran görüntüsü, örnek kodun örnek Excel dosyası üzerindeki etkisini gösterir. Ekran görüntüsünde görebileceğiniz gibi, ilk pivot alanı artık aylara ve çeyreklere göre gruplandırılmıştır.
Basit kod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Load sample workbook | |
Workbook wb = new Workbook("sampleGroupPivotFieldsInPivotTable.xlsx"); | |
//Access the second worksheet | |
Worksheet ws = wb.getWorksheets().get(1); | |
//Access the pivot table | |
PivotTable pt = ws.getPivotTables().get(0); | |
//Specify the start and end date time | |
DateTime dtStart = new DateTime(2008, 1, 1);//1-Jan-2018 | |
DateTime dtEnd = new DateTime(2008, 9, 5); //5-Sep-2018 | |
//Specify the group type list, we want to group by months and quarters | |
int[] groupTypeList = new int[2]; | |
groupTypeList[0] = PivotGroupByType.MONTHS; | |
groupTypeList[1] = PivotGroupByType.QUARTERS; | |
//Apply the grouping on the pivot field | |
PivotField field = pt.getRowFields().get(0); | |
field.groupBy(dtStart, dtEnd, groupTypeList, 1, true); | |
//Refresh and calculate pivot table | |
pt.setRefreshDataFlag(true); | |
pt.refreshData(); | |
pt.calculateData(); | |
pt.setRefreshDataFlag(false); | |
//Save the output Excel file | |
wb.save("outputGroupPivotFieldsInPivotTable.xlsx"); |