Table — Aspose.Cells FOSS for Python API Reference
aspose-cells-foss reprezintă tabelele structurate Excel (ListObjects) prin Table clasa și TableCollection accesibilă ca ws.list_objects. Tabelele oferă intervale denumite, filtrare automată, rânduri de antet și stilizare cu benzi pe rânduri încorporată în formatul XLSX.
ImageRenderOptions: aspose.cells_foss
from aspose.cells_foss import TableStyleInfo, TableColumnTableStyleInfo
Descrie stilul vizual aplicat unui tabel (benzi, evidențierea primei/ultimei coloane).
ImageRenderOptions
TableStyleInfo()ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | str | Nume de stil pentru tabelul Excel (de ex., "TableStyleMedium9"). |
show_first_column | bool | True pentru a aplica formatare specială primei coloane. |
show_last_column | bool | True pentru a aplica formatare specială ultimei coloane. |
show_row_stripes | bool | True pentru a aplica benzi alternante pe rânduri. |
show_column_stripes | bool | True pentru a aplica benzi alternante pe coloane. |
TableColumn
Descrie o singură coloană dintr-un tabel.
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 | Textul antetului coloanei. Trebuie să fie unic în cadrul tabelului. |
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
id | int | Identificatorul coloanei (doar citire). |
name | str | Textul antetului coloanei. |
totals_row_function | str | Funcție agregată afișată în rândul totalurilor: 'none', 'sum', 'average', 'count', 'countNums', 'max', 'min', 'stdDev', 'var', 'custom'. |
totals_row_label | str | Textul etichetei afișat în celula totalurilor când totals_row_function este 'none'. |
totals_row_formula | str | Formulă personalizată utilizată când totals_row_function este 'custom'. |
ImageRenderOptions
Table obiectele nu sunt construite direct. Utilizați ws.list_objects.add(...) sau ws.list_objects.add_with_range(...).
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
name | str | Nume intern al tabelului (trebuie să fie unic în registru, fără spații). |
display_name | str | Nume afișat în caseta de nume Excel. |
ref | str | Intervalul de celule acoperit de tabel (de ex., "A1:D10"). |
has_headers | bool | True dacă primul rând al intervalului conține antetele coloanelor. |
show_totals_row | bool | True pentru a afișa un rând cu totaluri de agregare în partea de jos a tabelului. |
show_auto_filter | bool | True pentru a afișa săgețile de filtrare automată în rândul de antet. |
table_style_info | TableStyleInfo | Setări de stil vizual (banding, evidențierea coloanelor). |
columns | list[TableColumn] | Listă ordonată de TableColumn obiecte (câte unul pentru fiecare coloană a tabelului). |
TableCollection
TableCollection este accesat ca ws.list_objects. Gestionează toate tabelele structurate pe o foaie de lucru.
ImageRenderOptions
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
) -> TableCreează un tabel peste intervalul de celule furnizat. Toate indecșii sunt 0-based. Dacă name este None, un nume este generat automat (de exemplu,., "Table1").
add_with_range
ws.list_objects.add_with_range(
cell_range: str,
name: str | None = None,
has_headers: bool = True
) -> TableCreează un tabel dintr-un șir de interval în stil A1 (de exemplu,., "A1:D10"). Mai ușor de citit decât add() pentru intervale codificate.
Proprietăți și iterare
| ImageRenderOptions | ImageRenderOptions |
|---|---|
count | Numărul de tabele din această foaie de lucru (doar citire). |
__len__() | ImageRenderOptions count. |
__iter__() | Iterează peste toate Table obiecte. |
__getitem__(index) | Returnează Table la bază zero index. |
ImageRenderOptions
Exemplul următor scrie un set de date de inventar de produse și îl convertește într-un tabel Excel stilizat cu un rând de totaluri.
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")