TableRow / TableCell — Aspose.Note FOSS for Python API Reference
클래스: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow 단일 행을 나타냅니다 Table.그 직접 자식은 TableCell 노드들.
ImageRenderOptions
TableRow 는 상속받은 것 외에 속성이 없습니다 CompositeNode 및 Node.
CompositeNode에서 상속됨
| 속성 / 메서드 | ImageRenderOptions |
|---|---|
FirstChild | 첫 번째 직접 자식 TableCell, 또는 None |
LastChild | 마지막 직접 자식 TableCell, 또는 None |
AppendChildLast(node) | 추가 TableCell |
AppendChildFirst(node) | 앞에 추가 TableCell |
InsertChild(index, node) | 삽입 TableCell 특정 위치에 |
RemoveChild(node) | 제거 TableCell |
GetChildNodes(Type) | 재귀적 깊이 우선 탐색 |
for cell in row | 직접 반복 TableCell 자식 |
Node로부터 상속됨
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | 포함하는 Table |
Document | 루트 Document |
클래스: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell 단일 셀을 나타냅니다 TableRow. 포함할 수 있습니다 RichText, Image, 및 기타 콘텐츠 노드를 자식으로 포함합니다.
ImageRenderOptions
TableCell 는 상속받은 것 외에 속성이 없습니다 CompositeNode 및 Node.
CompositeNode에서 상속됨
| 속성 / 메서드 | ImageRenderOptions |
|---|---|
FirstChild | 첫 번째 직접 콘텐츠 자식 |
LastChild | 마지막 직접 콘텐츠 자식 |
AppendChildLast(node) | 이 셀에 콘텐츠 노드를 추가합니다 |
AppendChildFirst(node) | 콘텐츠 노드를 앞에 삽입합니다 |
InsertChild(index, node) | 특정 위치에 삽입합니다 |
RemoveChild(node) | 콘텐츠 노드를 제거합니다 |
GetChildNodes(Type) | 재귀적 깊이 우선 탐색 |
for child in cell | 직접 자식을 순회합니다 |
Node로부터 상속됨
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | 포함하는 TableRow |
Document | 루트 Document |
사용 예시
모든 테이블 행과 셀을 반복합니다
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
print(f"Table column widths: {[col.Width for col in table.Columns]}")
for row in table.GetChildNodes(TableRow):
row_texts = []
for cell in row.GetChildNodes(TableCell):
texts = cell.GetChildNodes(RichText)
cell_text = " ".join(rt.Text for rt in texts if rt.Text)
row_texts.append(cell_text)
print(" |", " | ".join(row_texts), "|")각 셀에서 텍스트를 추출하여 평면 리스트로 만듭니다
from aspose.note import Document, TableCell, RichText
doc = Document("MyNotes.one")
for cell in doc.GetChildNodes(TableCell):
for rt in cell.GetChildNodes(RichText):
if rt.Text.strip():
print(rt.Text)프로그램적으로 테이블을 구축합니다
from aspose.note import (
Document, Page, Outline, OutlineElement,
Table, TableRow, TableCell, RichText, SaveFormat
)
doc = Document()
page = doc.AppendChildLast(Page())
outline = page.AppendChildLast(Outline())
elem = outline.AppendChildLast(OutlineElement())
from aspose.note import TableColumn
table = elem.AppendChildLast(Table(
IsBordersVisible=True,
Columns=[TableColumn(Width=100.0), TableColumn(Width=200.0)],
))
headers = ["Name", "Value"]
row = table.AppendChildLast(TableRow())
for header_text in headers:
cell = row.AppendChildLast(TableCell())
rt = cell.AppendChildLast(RichText())
rt.Append(header_text)
data_row = table.AppendChildLast(TableRow())
for value in ["Item A", "42"]:
cell = data_row.AppendChildLast(TableCell())
rt = cell.AppendChildLast(RichText())
rt.Append(value)
doc.Save("table-output.pdf", SaveFormat.Pdf)행과 셀의 수를 셉니다
from aspose.note import Document, Table, TableRow, TableCell
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
rows = table.GetChildNodes(TableRow)
cells = table.GetChildNodes(TableCell)
print(f"Rows: {len(rows)} Cells: {len(cells)}")None-안전
TableRow 그리고 TableCell nullable 자체 속성이 없습니다. 반환되는 자식 목록은 GetChildNodes 항상 목록이며 (비어 있을 수 있습니다).
참고
- ImageRenderOptions: TableRow의 부모
- RichText: TableCell 내의 기본 콘텐츠
- ImageRenderOptions: TableCell 내의 이미지 콘텐츠
- CompositeNode: 상속된 자식 관리 메서드