Table — Aspose.Cells FOSS for Python API Reference
aspose-cells-foss, Excel yapılandırılmış tablolarını (ListObjects) aracılığıyla temsil eder Table sınıf ve TableCollection olarak erişilebilir ws.list_objects. Tablolar, XLSX formatına yerleşik adlandırılmış aralıklar, otomatik filtre, başlık satırları ve şeritli satır stilini sağlar.
Enumerations: aspose.cells_foss
from aspose.cells_foss import TableStyleInfo, TableColumnTableStyleInfo
Bir tabloya uygulanan görsel stili (bantlama, ilk/son sütun vurguları) tanımlar.
Enumerations
TableStyleInfo()Enumerations
| Enumerations | Enumerations | Enumerations |
|---|---|---|
name | str | Excel tablo stil adı (ör.,)., "TableStyleMedium9"). |
show_first_column | bool | True ilk sütuna özel biçimlendirme uygulamak için. |
show_last_column | bool | True son sütuna özel biçimlendirme uygulamak için. |
show_row_stripes | bool | True alternatif satır bantlaması uygulamak için. |
show_column_stripes | bool | True alternatif sütun bantlaması uygulamak için. |
TableColumn
Bir tablo içindeki tek bir sütunu tanımlar.
Enumerations
TableColumn(col_id: int, name: str)| Enumerations | Enumerations | Enumerations |
|---|---|---|
col_id | int | 1-based column identifier within the table (not the worksheet column index). |
name | str | Sütun başlığı metni. Tablo içinde benzersiz olmalıdır. |
Enumerations
| Enumerations | Enumerations | Enumerations |
|---|---|---|
id | int | Sütun tanımlayıcısı (yalnızca okunabilir). |
name | str | Sütun başlığı metni. |
totals_row_function | str | Toplam satırında gösterilen toplama işlevi: 'none', 'sum', 'average', 'count', 'countNums', 'max', 'min', 'stdDev', 'var', 'custom'. |
totals_row_label | str | Toplam hücresinde gösterilen etiket metni, şu durumda: totals_row_function olduğunda 'none'. |
totals_row_formula | str | Şu durumda kullanılan özel formül totals_row_function olduğunda 'custom'. |
Enumerations
Table nesneler doğrudan oluşturulmaz. Kullan: ws.list_objects.add(...) veya ws.list_objects.add_with_range(...).
Enumerations
| Enumerations | Enumerations | Enumerations |
|---|---|---|
name | str | İç tablo adı (çalışma kitabında benzersiz olmalı, boşluk içermemelidir). |
display_name | str | Excel Ad Kutusunda gösterilen görüntü adı. |
ref | str | Tablonun kapsadığı hücre aralığı (örneğin,., "A1:D10"). |
has_headers | bool | True eğer aralığın ilk satırı sütun başlıklarını içeriyorsa. |
show_totals_row | bool | True tablonun alt kısmında bir toplama toplam satırı görüntülemek için. |
show_auto_filter | bool | True başlık satırında otomatik filtre açılır oklarını göstermek için. |
table_style_info | TableStyleInfo | Görsel stil ayarları (şeritleme, sütunları vurgulama). |
columns | list[TableColumn] | Sıralı liste TableColumn nesneler (her tablo sütunu için bir tane). |
TableCollection
TableCollection şu şekilde erişilir ws.list_objects. Çalışma sayfasındaki tüm yapılandırılmış tabloları yönetir.
Enumerations
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
) -> TableVerilen hücre aralığı üzerinde bir tablo oluşturur. Tüm indeksler 0-based. Eğer name şu ise None, bir ad otomatik olarak oluşturulur (örneğin,., "Table1").
add_with_range
ws.list_objects.add_with_range(
cell_range: str,
name: str | None = None,
has_headers: bool = True
) -> TableA1 biçimindeki bir aralık dizesinden tablo oluşturur (örneğin,., "A1:D10"). Daha okunaklı add() kod içinde sabitlenmiş aralıklar için.
Özellikler ve Yineleme
| Enumerations | Enumerations |
|---|---|
count | Bu çalışma sayfasındaki tablo sayısı (yalnızca okunur). |
__len__() | Enumerations count. |
__iter__() | Tümünü yineleyerek Table nesneler. |
__getitem__(index) | Döndürür Table sıfır tabanlı index. |
Enumerations
Aşağıdaki örnek bir ürün envanter veri kümesini yazar ve bunu toplam satırı içeren stilize bir Excel tablosuna dönüştürür.
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")