Table

aspose-cells-foss représente les tables structurées d’Excel (ListObjects) via le Table classe et le TableCollection accessible en tant que ws.list_objects. Les tables offrent des plages nommées, un filtre automatique, des lignes d’en‑tête et un style de bandes de lignes intégré au format XLSX.

Examples: aspose.cells_foss

from aspose.cells_foss import TableStyleInfo, TableColumn

TableStyleInfo

Décrit le style visuel appliqué à un tableau (bandes, mise en évidence de la première/dernière colonne).

Examples

TableStyleInfo()

Examples

NameTypeAccessDescription
name``ReadGets the name.
display_name``ReadGets the display name.
ref``ReadGets the ref.
has_headers``ReadGets the has headers.
show_totals_row``ReadGets the show totals row.
show_auto_filter``ReadGets the show auto filter.
table_style_info``ReadGets the table style info.
columnslistReadGets the columns.

TableColumn

Décrit une colonne unique au sein d’un tableau.

Examples

TableColumn(col_id: int, name: str)
SignatureDescription
__init__(name: str, ref: str, has_headers: bool)
copy()

Examples


Examples

Table les objets ne sont pas construits directement. Utilisez ws.list_objects.add(...) ou ws.list_objects.add_with_range(...).

Examples


TableCollection

TableCollection est accessible en tant que ws.list_objects. Il gère tous les tableaux structurés d’une feuille de calcul.

Examples

add

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

Crée un tableau sur la plage de cellules donnée. Tous les indices sont 0-based. Si name est None, un nom est généré automatiquement (par ex., "Table1").

add_with_range

ws.list_objects.add_with_range(
    cell_range: str,
    name: str | None = None,
    has_headers: bool = True
) -> Table

Crée un tableau à partir d’une chaîne de plage de style A1 (par ex., "A1:D10"). Plus lisible que add() pour les plages codées en dur.

Propriétés et itération


Examples

L’exemple suivant écrit un jeu de données d’inventaire de produits et le convertit en un tableau Excel stylisé avec une ligne de totaux.

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

Voir aussi

 Français