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

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

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

todo:image_alt_text

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

todo:image_alt_text

Pythonコードを使用して小計を適用し、アウトラインの方向を変更する方法

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

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(".")
# Create workbook from source Excel file
workbook = Workbook(dataDir + "Book1.xlsx")
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Get the Cells collection in the first worksheet
cells = worksheet.cells
# Create a cellarea i.e.., A2:B11
ca = CellArea.create_cell_area("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, [1 ], True, False, True)
# Set the direction of outline summary
worksheet.outline.summary_row_below = True
# Save the excel file
workbook.save(dataDir + "output_out.xlsx")