Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
ピボットテーブルは、インタラクティブなサマリー レポートです。行ごとに並ぶ大量の生データを、数式を一切使わずにコンパクトなマトリックスにまとめられます。どの列を行ラベルとするか、どの列を列ラベルとするか、どの列を集計して値とするかを指定すると、グループ化と計算はピボットテーブルが行います。
Aspose.Cells を使用すると、スプレッドシートにピボットテーブルを追加できます。Aspose.Cells には、ピボットテーブルの作成と制御用に用意された特殊なクラスがいくつかあります。これらのクラスは、ピボットテーブルの構成要素となる PivotTable オブジェクトを作成し、そのプロパティを設定するために使用されます。 ピボットテーブルオブジェクトは次のとおりです。
ピボットテーブルの作成は、3 つの主要ステップで構成されます。ソースデータをワークシートのセルに書き込み、指定した位置にピボットテーブルを追加して、ピボットフィールドを行領域、列領域、およびデータ領域に配置します。
putValue)を使用して、ワークシートのセルにデータを追加します。このデータはピボットテーブルのデータソースとして使用されます。add(sourceData, row, column))。sourceData はソース範囲です(例: “A1:C8”)。row と column は、ピボットテーブルの左上隅にある配置先セルの 0 ベースの座標です(セル E3 の場合は行 2、列 4)。このメソッドは、新しい PivotTable オブジェクトを直接返します。addFieldToArea メソッドを使用して、ピボットフィールドを配置します。フィールド名は、行領域 (PivotFieldType.ROW)、列領域 (PivotFieldType.COLUMN)、またはデータ領域 (PivotFieldType.DATA) に指定します。
import com.aspose.cells.*;
// 新しいワークブックを作成し、最初のワークシートを取得する
Workbook workbook = new Workbook();
Worksheet sheet = workbook.getWorksheets().get(0);
Cells cells = sheet.getCells();
// ソースデータを書き込む:スポーツ別および四半期別の売上
cells.get("A1").putValue("Sport");
cells.get("B1").putValue("Quarter");
cells.get("C1").putValue("Sales");
cells.get("A2").putValue("Golf");
cells.get("B2").putValue("Qtr3");
cells.get("C2").putValue(1500);
cells.get("A3").putValue("Golf");
cells.get("B3").putValue("Qtr4");
cells.get("C3").putValue(2000);
cells.get("A4").putValue("Tennis");
cells.get("B4").putValue("Qtr3");
cells.get("C4").putValue(600);
cells.get("A5").putValue("Tennis");
cells.get("B5").putValue("Qtr4");
cells.get("C5").putValue(1500);
cells.get("A6").putValue("Tennis");
cells.get("B6").putValue("Qtr3");
cells.get("C6").putValue(4070);
cells.get("A7").putValue("Tennis");
cells.get("B7").putValue("Qtr4");
cells.get("C7").putValue(5000);
cells.get("A8").putValue("Golf");
cells.get("B8").putValue("Qtr3");
cells.get("C8").putValue(6430);
// 宛先セル E3 に、A1:C8 をソースとするピボットテーブルを追加する
PivotTable pivotTable = sheet.getPivotTables().add("A1:C8", 2, 4);
// ピボットフィールドを割り当てる:Sport を Rows に、Quarter を Columns に、Sales を Data に
pivotTable.addFieldToArea(PivotFieldType.ROW, "Sport");
pivotTable.addFieldToArea(PivotFieldType.COLUMN, "Quarter");
pivotTable.addFieldToArea(PivotFieldType.DATA, "Sales");
// ワークブックを保存する
workbook.save("pivotTable_test_out.xlsx");
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.