Table
Table — Aspose.Cells FOSS for Python API Reference
aspose-cells-foss は Excel の構造化テーブル (ListObjects) を通じて Table クラスと TableCollection としてアクセス可能 ws.list_objects. テーブルは、XLSX 形式に組み込まれた名前付き範囲、オートフィルタ、ヘッダー行、およびバンド行スタイリングを提供します。.
ImageRenderOptions: aspose.cells_foss
from aspose.cells_foss import TableStyleInfo, TableColumnTableStyleInfo
テーブルに適用されるビジュアルスタイル(バンド、最初/最後の列のハイライト)を説明します。.
ImageRenderOptions
TableStyleInfo()ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | str | Excel テーブル スタイル名(例:., "TableStyleMedium9"). |
show_first_column | bool | True 最初の列に特別な書式設定を適用するために。. |
show_last_column | bool | True 最後の列に特別な書式設定を適用するために。. |
show_row_stripes | bool | True 交互の行バンドを適用するために。. |
show_column_stripes | bool | True 交互の列バンドを適用するために。. |
TableColumn
テーブル内の単一列を説明します。.
ImageRenderOptions
TableColumn(col_id: int, name: str)| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
col_id | int | 1-based column identifier within the table (not the worksheet column index). |
name | str | 列ヘッダーのテキスト。テーブル内で一意である必要があります。. |
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
id | int | 列識別子(読み取り専用)。. |
name | str | 列ヘッダーのテキスト。. |
totals_row_function | str | 合計行に表示される集計関数:: 'none', 'sum', 'average', 'count', 'countNums', 'max', 'min', 'stdDev', 'var', 'custom'. |
totals_row_label | str | 合計セルに表示されるラベルテキストは totals_row_function です 'none'. |
totals_row_formula | str | カスタム数式は次の場合に使用されます totals_row_function です 'custom'. |
ImageRenderOptions
Table オブジェクトは直接構築されません。次を使用してください ws.list_objects.add(...) または ws.list_objects.add_with_range(...).
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | str | 内部テーブル名(ブック内で一意である必要があり、スペースは使用できません)。. |
display_name | str | Excel の名前ボックスに表示される表示名。. |
ref | str | テーブルがカバーするセル範囲(例:., "A1:D10"). |
has_headers | bool | True 範囲の最初の行に列ヘッダーが含まれている場合。. |
show_totals_row | bool | True テーブルの下部に集計合計行を表示するため。. |
show_auto_filter | bool | True ヘッダー行にオートフィルタのドロップダウン矢印を表示するため。. |
table_style_info | TableStyleInfo | ビジュアルスタイル設定(バンディング、列のハイライト)。. |
columns | list[TableColumn] | 順序付きリスト TableColumn オブジェクト(テーブル列ごとに1つ)。. |
TableCollection
TableCollection は次のようにアクセスされます ws.list_objects.。ワークシート上のすべての構造化テーブルを管理します。.
ImageRenderOptions
追加
ws.list_objects.add(
start_row: int,
start_col: int,
end_row: int,
end_col: int,
has_headers: bool = True,
name: str | None = None
) -> Table指定されたセル範囲にテーブルを作成します。すべてのインデックスは 0-based.。もし name です None, 名前は自動的に生成されます(例:., "Table1").
add_with_range
ws.list_objects.add_with_range(
cell_range: str,
name: str | None = None,
has_headers: bool = True
) -> TableA1 形式の範囲文字列からテーブルを作成します(例:., "A1:D10"). より読みやすい add() ハードコードされた範囲の場合。.
プロパティとイテレーション
| ImageRenderOptions | ImageRenderOptions |
|---|---|
count | このワークシート上のテーブル数(読み取り専用)。. |
__len__() | ImageRenderOptions count. |
__iter__() | すべてを反復処理します Table オブジェクト。. |
__getitem__(index) | 返します Table ゼロベースで index. |
ImageRenderOptions
以下の例は製品在庫データセットを書き込み、合計行付きのスタイル化された Excel テーブルに変換します。.
from aspose.cells_foss import Workbook
wb = Workbook()
ws = wb.worksheets[0]
ws.name = "Inventory"
# Write header and data rows
headers = ["SKU", "Product", "Qty", "Unit Price"]
rows = [
["A001", "Widget Alpha", 150, 12.99],
["A002", "Widget Beta", 80, 24.50],
["A003", "Gadget Gamma", 45, 49.99],
["A004", "Gadget Delta", 210, 8.75],
]
for col, h in enumerate(headers):
ws.cells[0][col].put_value(h)
for row_i, row in enumerate(rows, start=1):
for col_i, val in enumerate(row):
ws.cells[row_i][col_i].put_value(val)
# Create a table over A1:D5
table = ws.list_objects.add_with_range("A1:D5", name="InventoryTable")
# Configure style
table.table_style_info.name = "TableStyleMedium9"
table.table_style_info.show_row_stripes = True
table.table_style_info.show_first_column = False
table.table_style_info.show_last_column = False
# Add a totals row with sum on Qty and Unit Price columns
table.show_totals_row = True
table.columns[2].totals_row_function = "sum" # Qty
table.columns[3].totals_row_function = "sum" # Unit Price
table.columns[0].totals_row_label = "Total"
wb.save("inventory_table.xlsx")