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

Classe: TableRow

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

TableRow representa una fila única dins d’un Table. Els fills directes són TableCell nodes.


Properties

TableRow no té propietats més enllà de les heretades de CompositeNode i Node.

Heretat de CompositeNode

Propietat / MètodeProperties
FirstChildPrimer fill directe TableCell, o None
LastChildÚltim fill directe TableCell, o None
AppendChildLast(node)Afegeix un TableCell
AppendChildFirst(node)Anteposa un TableCell
InsertChild(index, node)Insereix un TableCell en una posició específica
RemoveChild(node)Elimina un TableCell
GetChildNodes(Type)Cerca recursiva en profunditat
for cell in rowItera directament TableCell fills

Heretat de Node

PropertiesProperties
ParentNodeEl contenidor Table
DocumentL’arrel Document

Classe: TableCell

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

TableCell representa una única cel·la dins d’un TableRow. Pot contenir RichText, Image, i altres nodes de contingut com a fills.


Properties

TableCell no té propietats més enllà de les heretades de CompositeNode i Node.

Heretat de CompositeNode

Propietat / MètodeProperties
FirstChildPrimer fill directe de contingut
LastChildÚltim fill directe de contingut
AppendChildLast(node)Afegeix un node de contingut a aquesta cel·la
AppendChildFirst(node)Afegeix un node de contingut al principi
InsertChild(index, node)Insereix en una posició específica
RemoveChild(node)Elimina un node de contingut
GetChildNodes(Type)Cerca recursiva en profunditat
for child in cellItera els fills directes

Heretat de Node

PropertiesProperties
ParentNodeEl contenidor TableRow
DocumentL’arrel Document

Exemples d’ús

Iterar totes les files i cel·les de la taula

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

Extreure el text de cada cel·la com una llista plana

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)

Construir una taula programàticament

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)

Comptar files i cel·les

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

Seguretat contra None

TableRow i TableCell no tenen propietats pròpies nul·les. Les llistes de fills retornades per GetChildNodes són sempre llistes (poden estar buides).


Vegeu també

 Català