Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Cells を使用すると、ピボットテーブルをスプレッドシートにプログラムで追加できます。
Aspose.Cells は、ピボットテーブルの作成と制御に使用されるクラスのセットを提供します。構成要素は次のとおりです:
PivotField は PivotTable 内のフィールドを表します。PivotFieldCollection は PivotTable 内のすべての PivotField オブジェクトのコレクションを表します。PivotTable はワークシート上のピボットテーブルを表します。PivotTableCollection はワークシート上のすべての PivotTable オブジェクトのコレクションを表します。putValue メソッドを使用してワークシートにデータを追加します。このデータはピボットテーブルのデータソースとして使用されます。PivotTables コレクションの add メソッドを呼び出して、ワークシートにピボットテーブルを追加します。PivotTables コレクションから新しい PivotTable オブジェクトにアクセスします。PivotTable オブジェクトのいずれかを使用して、ピボットテーブルを管理します。サンプル コードを実行すると、ピボットテーブルがワークシートに追加されます。
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook, PivotFieldType
dataDir = "./"
workbook = Workbook()
sheet = workbook.getWorksheets().get(0)
cells = sheet.getCells()
cell = cells.get("A1")
cell.putValue("Sport")
cell = cells.get("B1")
cell.putValue("Quarter")
cell = cells.get("C1")
cell.putValue("Sales")
cell = cells.get("A2")
cell.putValue("Golf")
cell = cells.get("A3")
cell.putValue("Golf")
cell = cells.get("A4")
cell.putValue("Tennis")
cell = cells.get("A5")
cell.putValue("Tennis")
cell = cells.get("A6")
cell.putValue("Tennis")
cell = cells.get("A7")
cell.putValue("Tennis")
cell = cells.get("A8")
cell.putValue("Golf")
cell = cells.get("B2")
cell.putValue("Qtr3")
cell = cells.get("B3")
cell.putValue("Qtr4")
cell = cells.get("B4")
cell.putValue("Qtr3")
cell = cells.get("B5")
cell.putValue("Qtr4")
cell = cells.get("B6")
cell.putValue("Qtr3")
cell = cells.get("B7")
cell.putValue("Qtr4")
cell = cells.get("B8")
cell.putValue("Qtr3")
cell = cells.get("C2")
cell.putValue(1500)
cell = cells.get("C3")
cell.putValue(2000)
cell = cells.get("C4")
cell.putValue(600)
cell = cells.get("C5")
cell.putValue(1500)
cell = cells.get("C6")
cell.putValue(4070)
cell = cells.get("C7")
cell.putValue(5000)
cell = cells.get("C8")
cell.putValue(6430)
pivotTables = sheet.getPivotTables()
index = pivotTables.add("=A1:C8", "E3", "PivotTable2")
pivotTable = pivotTables.get(index)
pivotTable.setRowGrand(False)
pivotTable.addFieldToArea(PivotFieldType.ROW, 0)
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 1)
pivotTable.addFieldToArea(PivotFieldType.DATA, 2)
workbook.save(dataDir + "pivotTable_test_out.xls")
jpype.shutdownJVM()
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.