TableRow / TableCell

TableRow / TableCell — Aspose.Note FOSS for Python API Reference

Clasa: TableRow

ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode

TableRow reprezintă un rând unic într-un Table. Copiii săi direcți sunt TableCell noduri.


ImageRenderOptions

TableRow nu are proprietăți în afara celor moștenite de la CompositeNode și Node.

Moștenit de la CompositeNode

Proprietate / MetodăImageRenderOptions
FirstChildPrimul copil direct TableCell, sau None
LastChildUltimul copil direct TableCell, sau None
AppendChildLast(node)Adaugă un TableCell
AppendChildFirst(node)Adaugă la început un TableCell
InsertChild(index, node)Inserează un TableCell la o poziție specifică
RemoveChild(node)Elimină un TableCell
GetChildNodes(Type)Căutare recursivă în adâncime
for cell in rowIterează direct TableCell copii

Moștenit de la Node

ImageRenderOptionsImageRenderOptions
ParentNodeCel care conține Table
DocumentRădăcina Document

Clasa: TableCell

ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode

TableCell reprezintă o singură celulă într-un TableRow. Poate conține RichText, Image, și alte noduri de conținut ca și copii.


ImageRenderOptions

TableCell nu are proprietăți în afara celor moștenite de la CompositeNode și Node.

Moștenit de la CompositeNode

Proprietate / MetodăImageRenderOptions
FirstChildPrimul copil de conținut direct
LastChildUltimul copil de conținut direct
AppendChildLast(node)Adaugă un nod de conținut la această celulă
AppendChildFirst(node)Adaugă un nod de conținut la început
InsertChild(index, node)Inserează la o poziție specifică
RemoveChild(node)Elimină un nod de conținut
GetChildNodes(Type)Căutare recursivă depth-first
for child in cellIterați copiii direcți

Moștenit de la Node

ImageRenderOptionsImageRenderOptions
ParentNodeCel care conține TableRow
DocumentRădăcina Document

Exemple de utilizare

Iterați toate rândurile și celulele tabelului

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), "|")

Extrageți textul din fiecare celulă ca o listă plată

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)

Construiți un tabel programatic

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)

Numărați rândurile și celulele

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)}")

Siguranță None

TableRow și TableCell nu au proprietăți proprii care pot fi nule. Listele de copii returnate de GetChildNodes sunt întotdeauna liste (pot fi goale).


Vezi și

 Română