Table
aspose-cells-foss rappresenta le tabelle strutturate di Excel (ListObjects) attraverso il Table classe e il TableCollection accessibile come ws.list_objects. Le tabelle forniscono intervalli denominati, filtro automatico, righe di intestazione e stile a bande di righe integrato nel formato XLSX.
ImageRenderOptions: aspose.cells_foss
from aspose.cells_foss import TableStyleInfo, TableColumnTableStyleInfo
Descrive lo stile visivo applicato a una tabella (bande, evidenziazione della prima/ultima colonna).
ImageRenderOptions
TableStyleInfo()ImageRenderOptions
| Name | Type | Access | Description |
|---|---|---|---|
name | `` | Read | Gets the name. |
display_name | `` | Read | Gets the display name. |
ref | `` | Read | Gets the ref. |
has_headers | `` | Read | Gets the has headers. |
show_totals_row | `` | Read | Gets the show totals row. |
show_auto_filter | `` | Read | Gets the show auto filter. |
table_style_info | `` | Read | Gets the table style info. |
columns | list | Read | Gets the columns. |
TableColumn
Descrive una singola colonna all’interno di una tabella.
ImageRenderOptions
TableColumn(col_id: int, name: str)| Signature | Description |
|---|---|
__init__(name: str, ref: str, has_headers: bool) | |
copy() |
ImageRenderOptions
ImageRenderOptions
Table gli oggetti non sono costruiti direttamente. Usa ws.list_objects.add(...) oppure ws.list_objects.add_with_range(...).
ImageRenderOptions
TableCollection
TableCollection è accessibile come ws.list_objects. Gestisce tutte le tabelle strutturate in un foglio di lavoro.
ImageRenderOptions
aggiungi
ws.list_objects.add(
start_row: int,
start_col: int,
end_row: int,
end_col: int,
has_headers: bool = True,
name: str | None = None
) -> TableCrea una tabella sull’intervallo di celle specificato. Tutti gli indici sono 0-based. Se name è None, un nome viene generato automaticamente (ad esempio,., "Table1").
add_with_range
ws.list_objects.add_with_range(
cell_range: str,
name: str | None = None,
has_headers: bool = True
) -> TableCrea una tabella da una stringa di intervallo in stile A1 (ad esempio,., "A1:D10"). Più leggibile di add() per intervalli codificati.
Proprietà e iterazione
ImageRenderOptions
Il seguente esempio scrive un dataset di inventario prodotti e lo converte in una tabella Excel stilizzata con una riga dei totali.
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")