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étodo | Examples |
|---|---|
FirstChild | Primer 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 row | Iterar directo TableCell hijos |
Hereda de Node
| Examples | Examples |
|---|---|
ParentNode | El contenedor Table |
Document | La 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étodo | Examples |
|---|---|
FirstChild | Primer 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 cell | Iterar hijos directos |
Hereda de Node
| Examples | Examples |
|---|---|
ParentNode | El contenedor TableRow |
Document | La 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
- Examples: padre de TableRow
- RichText: contenido principal dentro de TableCell
- Examples: contenido de imagen dentro de TableCell
- CompositeNode: métodos heredados de gestión de hijos