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 객체 (표 열당 하나). |
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 0 기반에서 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")