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

ソースファイルと出力ファイルの画像

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

todo:image_alt_text

サンプルコードによって生成されたExcelファイルの出力画面が以下に表示されています。範囲A2:B11に小計が適用されたことがわかります。また、アウトラインの方向は、詳細の下に集計行が表示されます。

todo:image_alt_text

サブトータルの適用とアウトラインサマリー行の方向変更のためのC#コード

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

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create workbook from source Excel file
Workbook workbook = new Workbook(dataDir + "Book1.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Get the Cells collection in the first worksheet
Cells cells = worksheet.Cells;
// 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.Outline.SummaryRowBelow = true;
// Save the excel file
workbook.Save(dataDir + "output_out.xlsx");