小計の作成

Microsoft エクセルを使う

Microsoft Excel で小計を作成するには:

  1. ワークブックの最初のワークシートに簡単なデータ リストを作成し (下図を参照)、ファイルを Book1.xls として保存します。

  2. リスト内の任意のセルを選択します。

  3. からデータメニュー、選択小計. 小計ダイアログが表示されます。使用する関数と小計を配置する場所を定義します。

    小計を追加するデータ範囲の選択

todo:画像_代替_文章

小計ダイアログ

todo:画像_代替_文章

Aspose.Cells API を使用

Aspose.Cells はクラスを提供し、ワークブックMicrosoft Excel ファイルを表します。のワークブッククラスにはワークシート コレクションこれにより、Excel ファイル内の各ワークシートにアクセスできます。

ワークシートは、ワークシートクラス。このクラスは、ワークシートやその他のオブジェクトを管理するための幅広いプロパティとメソッドを提供します。各ワークシートは、Cellsコレクション。ワークシートで小計を作成するには、Cellsクラスの小計メソッド。メソッドのパラメーターに適切な値を指定して、必要な結果を取得します。

次の例は、Aspose.Cells API を使用して、テンプレート ファイル (Book1.xls) の最初のワークシートに小計を作成する方法を示しています。

コードが実行されると、小計を含むワークシートが作成されます。

小計の適用

todo:画像_代替_文章

// 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");