TableRow / TableCell

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

Clase: TableRow

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

TableRow representa una fila única dentro de un Table. Sus hijos directos son TableCell nodos.


Examples

TableRow no tiene propiedades más allá de las heredadas de CompositeNode y Node.

Heredado de CompositeNode

Propiedad / MétodoExamples
FirstChildPrimer hijo directo TableCell, o None
LastChildÚltimo hijo directo TableCell, o None
AppendChildLast(node)Añadir un TableCell
AppendChildFirst(node)Anteponer un TableCell
InsertChild(index, node)Insertar un TableCell en una posición específica
RemoveChild(node)Eliminar un TableCell
GetChildNodes(Type)Búsqueda recursiva en profundidad
for cell in rowIterar directo TableCell hijos

Hereda de Node

ExamplesExamples
ParentNodeEl contenedor Table
DocumentLa raíz Document

Clase: TableCell

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

TableCell representa una única celda dentro de un TableRow. Puede contener RichText, Image, y otros nodos de contenido como hijos.


Examples

TableCell no tiene propiedades más allá de las heredadas de CompositeNode y Node.

Heredado de CompositeNode

Propiedad / MétodoExamples
FirstChildPrimer hijo directo de contenido
LastChildÚltimo hijo directo de contenido
AppendChildLast(node)Agregar un nodo de contenido a esta celda
AppendChildFirst(node)Anteponer un nodo de contenido
InsertChild(index, node)Insertar en una posición específica
RemoveChild(node)Eliminar un nodo de contenido
GetChildNodes(Type)Búsqueda recursiva en profundidad
for child in cellIterar hijos directos

Hereda de Node

ExamplesExamples
ParentNodeEl contenedor TableRow
DocumentLa raíz Document

Ejemplos de uso

Iterar todas las filas y celdas de la tabla

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

Extraer texto de cada celda como una lista 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 tabla programáticamente

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)

Contar filas y celdas

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

Seguridad contra None

TableRow y TableCell no tienen propiedades propias anulables. Las listas de hijos devueltas por GetChildNodes siempre son listas (pueden estar vacías).


Ver también

 Español