小計の作成
Contents
[
Hide
]
スプレッドシートで繰り返される値の小計を自動的に作成できます。 Aspose.Cells は、小計をスプレッドシートにプログラムで追加するのに役立つ API 機能を提供します。
Microsoft エクセルを使う
Microsoft Excel で小計を作成するには:
-
ワークブックの最初のワークシートに簡単なデータ リストを作成し (下図を参照)、ファイルを Book1.xls として保存します。
-
リスト内の任意のセルを選択します。
-
からデータメニュー、選択小計. 小計ダイアログが表示されます。使用する関数と小計を配置する場所を定義します。
小計を追加するデータ範囲の選択
小計ダイアログ
Aspose.Cells API を使用
Aspose.Cells はクラスを提供し、ワークブックMicrosoft Excel ファイルを表します。のワークブッククラスにはワークシート コレクションこれにより、Excel ファイル内の各ワークシートにアクセスできます。
ワークシートは、ワークシートクラス。このクラスは、ワークシートやその他のオブジェクトを管理するための幅広いプロパティとメソッドを提供します。各ワークシートは、Cellsコレクション。ワークシートで小計を作成するには、Cellsクラスの小計メソッド。メソッドのパラメーターに適切な値を指定して、必要な結果を取得します。
次の例は、Aspose.Cells API を使用して、テンプレート ファイル (Book1.xls) の最初のワークシートに小計を作成する方法を示しています。
コードが実行されると、小計を含むワークシートが作成されます。
小計の適用
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreatingSubtotals.class) + "data/"; | |
// Instantiate a new workbook | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Get the Cells collection in the first worksheet | |
Cells cells = workbook.getWorksheets().get(0).getCells(); | |
// Create a cellarea i.e.., B3:C19 | |
CellArea ca = new CellArea(); | |
ca.StartRow = 2; | |
ca.StartColumn = 1; | |
ca.EndRow = 18; | |
ca.EndColumn = 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, new int[] { 1 }); | |
// Save the excel file | |
workbook.save(dataDir + "CreatingSubtotals_out.xls"); | |
// Print message | |
System.out.println("Process completed successfully"); |