ピボットテーブルのデータを非表示にしたり並べ替えたり
Contents
[
Hide
]
ピボットテーブルのデータを非表示にしたり並べ替えたり
Aspose.Cellsは、ピボットテーブル内のデータを非表示および並べ替える機能をサポートしています。次のコードスニペットは、Score列を降順でソートし、スコアが60未満の行を非表示にする方法を示しています。
This file contains 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-.NET | |
// directories | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "PivotTableHideAndSortSample.xlsx"); | |
Worksheet worksheet = workbook.Worksheets[0]; | |
var pivotTable = worksheet.PivotTables[0]; | |
var dataBodyRange = pivotTable.DataBodyRange; | |
int currentRow = 3; | |
int rowsUsed = dataBodyRange.EndRow; | |
// Sorting score in descending | |
PivotField field = pivotTable.RowFields[0]; | |
field.IsAutoSort = true; | |
field.IsAscendSort = false; | |
field.AutoSortField = 0; | |
pivotTable.RefreshData(); | |
pivotTable.CalculateData(); | |
// Hiding rows with score less than 60 | |
while (currentRow < rowsUsed) | |
{ | |
Cell cell = worksheet.Cells[currentRow, 1]; | |
double score = Convert.ToDouble(cell.Value); | |
if (score < 60) | |
{ | |
worksheet.Cells.HideRow(currentRow); | |
} | |
currentRow++; | |
} | |
pivotTable.RefreshData(); | |
pivotTable.CalculateData(); | |
// Saving the Excel file | |
workbook.Save(outputDir + "PivotTableHideAndSort_out.xlsx"); |
コードスニペットで使用されているソースと出力のExcelファイルは、参照用に添付されています。