集計の作成

Microsoft Excel の使用

Microsoft Excel でサブトータルを追加する方法:

  1. ブック1.xlsとして保存、ブックの最初のワークシートに簡単なデータリストを作成します(以下の図を参照)。
  2. リスト内の任意のセルを選択します。
  3. データ メニューから、サブトータル を選択します。サブトータルのダイアログが表示されます。使用する関数とサブトータルを配置する場所を定義します。

Aspose.Cells for Python via .NET APIを使用する

Aspose.Cells for Python via .NET は、Microsoft Excelファイルを表す Workbook クラスを提供します。Workbook クラスには、Excelファイル内の各ワークシートにアクセスできる worksheets コレクションが含まれています。

ワークシートは Worksheet クラスによって表されます。このクラスはワークシートや他のオブジェクトの管理に幅広いプロパティとメソッドを提供します。各ワークシートには Cells コレクションが含まれています。ワークシートにサブトータルを追加するには、Cells クラスの subtotal メソッドを使用します。メソッドにパラメータ値を指定して、サブトータルの計算方法と配置を指定します。

以下の例では、Aspose.Cells for Python via .NET APIを使用して、テンプレートファイル (Book1.xls) の最初のワークシートにサブトータルを追加しました。コードを実行すると、サブトータルが含まれるワークシートが作成されます。

以下のコードスニペットは、Aspose.Cells for Python via .NETでワークシートにサブトータルを追加する方法を示しています。

from aspose.cells import CellArea, ConsolidationFunction, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a new workbook
# Open the template file
workbook = Workbook(dataDir + "book1.xls")
# Get the Cells collection in the first worksheet
cells = workbook.worksheets[0].cells
# Create a cellarea i.e.., B3:C19
ca = CellArea()
ca.start_row = 2
ca.start_column = 1
ca.end_row = 18
ca.end_column = 2
# Apply subtotal, the consolidation function is Sum and it will applied to
# Second column (C) in the list
cells.subtotal(ca, 0, ConsolidationFunction.SUM, [1 ])
# Save the excel file
workbook.save(dataDir + "output.out.xls")

高度なトピック