小計を適用し、詳細以下のアウトラインサマリー行を変更する

サンプルコードでソースと出力ファイルを比較するスクリーンショット

次のスクリーンショットは、以下のサンプルコードで使用されるソース Excel ファイルを示しており、列 A と列 B にいくつかのデータが含まれています。

todo:image_alt_text

次のスクリーンショットは、サンプルコードによって生成された出力 Excel ファイルを示しています。範囲 A2:B11 に小計が適用され、アウトラインの方向が詳細行の下になっていることがわかります。

todo:image_alt_text

小計を適用し、詳細の下にアウトラインサマリー行の方向を変更するための Java コード

次に示すコードは、上記の出力を実現するサンプルコードです。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//directories
String sourceDir = Utils.Get_SourceDirectory();
String outputDir = Utils.Get_OutputDirectory();
// Create workbook from source Excel file
Workbook workbook = new Workbook(sourceDir + "SampleSubtotal.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Get the Cells collection in the first worksheet
Cells cells = worksheet.getCells();
// Create a cellarea i.e.., A2:B11
CellArea ca = CellArea.createCellArea("A2", "B11");
// Apply subtotal, the consolidation function is Sum and it will applied to
// Second column (B) in the list
cells.subtotal(ca, 0, ConsolidationFunction.SUM, new int[] { 1 }, true, false, true);
// Set the direction of outline summary
worksheet.getOutline().setSummaryRowBelow(true);
// Save the excel file
workbook.save(outputDir + "ASubtotal_out.xlsx");