Table, TableRow, TableCell — Aspose.Note FOSS for Python API Reference
Clase: Table
Examples: aspose.note Examples: from aspose.note import Table Examples: CompositeNode
Table representa una tabla dentro de un OutlineElement.Contiene una lista de TableRow hijos y expone los anchos de columna y la visibilidad de los bordes.
Examples
| Examples | Examples | Examples | Examples |
|---|---|---|---|
ColumnWidths | list[float] | Examples | Ancho de cada columna en puntos; la longitud equivale al número de columnas |
BordersVisible | bool | Examples | Si los bordes de la tabla se renderizan en OneNote |
Tags | list[NoteTag] | Examples | Etiquetas de OneNote adjuntas a esta tabla |
Hereda de CompositeNode / Node
FirstChild, LastChild, GetChildNodes(Type), for row in table, ParentNode, Document
Clase: TableRow
Examples: aspose.note Examples: from aspose.note import TableRow Examples: CompositeNode
TableRow es una única fila dentro de un Table.Sus hijos directos son TableCell nodos.
Examples
rows = table.GetChildNodes(TableRow)
for row in rows:
cells = row.GetChildNodes(TableCell)Clase: TableCell
Examples: aspose.note Examples: from aspose.note import TableCell Examples: CompositeNode
TableCell es una única celda dentro de un TableRow.Puede contener RichText, Image, y otros nodos de contenido.
Examples
for cell in row.GetChildNodes(TableCell):
text = " ".join(rt.Text for rt in cell.GetChildNodes(RichText))Ejemplos de uso
Leer todas las tablas: recorrido completo
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("MyNotes.one")
for t_num, table in enumerate(doc.GetChildNodes(Table), start=1):
print(f"\nTable {t_num} cols={len(table.ColumnWidths)} widths={table.ColumnWidths}")
for r_num, row in enumerate(table.GetChildNodes(TableRow), start=1):
cells = row.GetChildNodes(TableCell)
row_data = [
" ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
for cell in cells
]
print(f" Row {r_num}: {row_data}")Exportar tablas a CSV
import csv, io
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("MyNotes.one")
buf = io.StringIO()
writer = csv.writer(buf)
for table in doc.GetChildNodes(Table):
for row in table.GetChildNodes(TableRow):
values = [
" ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
for cell in row.GetChildNodes(TableCell)
]
writer.writerow(values)
writer.writerow([])
csv_text = buf.getvalue()
print(csv_text)Contar filas y columnas
from aspose.note import Document, Table, TableRow, TableCell
doc = Document("MyNotes.one")
for i, table in enumerate(doc.GetChildNodes(Table), start=1):
rows = table.GetChildNodes(TableRow)
cols = len(rows[0].GetChildNodes(TableCell)) if rows else 0
print(f"Table {i}: {len(rows)} row(s) x {cols} column(s)")Tablas con imágenes en celdas
Las celdas pueden contener Image nodos junto a o en lugar de RichText:
from aspose.note import Document, Table, TableRow, TableCell, RichText, Image
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
for row in table.GetChildNodes(TableRow):
for cell in row.GetChildNodes(TableCell):
texts = cell.GetChildNodes(RichText)
images = cell.GetChildNodes(Image)
if images:
print(f" Cell with {len(images)} image(s) and {len(texts)} text(s)")Inspeccionar etiquetas en una tabla
from aspose.note import Document, Table
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
for tag in table.Tags:
print(f"Table tag: {tag.label!r} completed={tag.completed}")Posición DOM
OutlineElement
└── Table
└── TableRow (0..n)
└── TableCell (0..n)
├── RichText (0..n)
└── Image (0..n)Table siempre es un hijo de OutlineElement. Usar table.ParentNode para acceder al contenedor OutlineElement.
Ver también
- RichText: contenido de texto dentro de las celdas
- Examples: contenido de imagen dentro de las celdas
- Guía del desarrollador para el análisis de tablas
- Cómo analizar tablas (KB)
- Blog: Analizar tablas de OneNote en Python