C++を使用してピボットテーブルのDataFieldのデータ表示形式を操作
Contents
[
Hide
]
Aspose.Cellsは、データフィールドのすべての表示形式をサポートしています。
“最小から最大までの順位付け"および"最大から最小までの順位付け"表示形式オプション
Aspose.Cellsは、ピボットフィールドの表示形式オプションを設定する機能を提供します。これには、PivotField.GetCalculationType()プロパティを使用します。最大から最小までランク付けする場合は、PivotField.GetCalculationType()プロパティをPivotFieldDataDisplayFormat.RankLargestToSmallestに設定できます。以下のコードスニペットは、表示形式オプションの設定例です。
サンプルソースと出力ファイルは、テスト用のサンプルコードをダウンロードできます:
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Pivot;
int main()
{
Aspose::Cells::Startup();
// Source and output directories
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Load a template file
Workbook workbook(srcDir + u"PivotTableSample.xlsx");
// Get the first worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
int pivotIndex = 0;
// Accessing the PivotTable
PivotTable pivotTable = worksheet.GetPivotTables().Get(pivotIndex);
// Accessing the data fields
PivotFieldCollection pivotFields = pivotTable.GetDataFields();
// Accessing the first data field in the data fields
PivotField pivotField = pivotFields.Get(0);
// Setting data display format
pivotField.GetShowValuesSetting().SetCalculationType(PivotFieldDataDisplayFormat::RankLargestToSmallest);
// Calculate data
pivotTable.CalculateData();
// Saving the Excel file
workbook.Save(outDir + u"PivotTableDataDisplayFormatRanking_out.xlsx");
std::cout << "PivotTable data display format ranking applied successfully!" << std::endl;
Aspose::Cells::Cleanup();
}