Table, TableRow, TableCell — Aspose.Note FOSS for Python API Reference
Classe: Table
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import Table ImageRenderOptions: CompositeNode
Table representa uma tabela dentro de um OutlineElement.contém uma lista de TableRow filhos e expõe larguras de colunas e visibilidade de bordas.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
ColumnWidths | list[float] | ImageRenderOptions | Largura de cada coluna em pontos; o comprimento equivale ao número de colunas |
BordersVisible | bool | ImageRenderOptions | Se as bordas da tabela são renderizadas no OneNote |
Tags | list[NoteTag] | ImageRenderOptions | Tags do OneNote anexadas a esta tabela |
Herda de CompositeNode / Node
FirstChild, LastChild, GetChildNodes(Type), for row in table, ParentNode, Document
Classe: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow é uma única linha dentro de um Table.Seus filhos diretos são TableCell nós.
ImageRenderOptions
rows = table.GetChildNodes(TableRow)
for row in rows:
cells = row.GetChildNodes(TableCell)Classe: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell é uma única célula dentro de um TableRow.Pode conter RichText, Image, e outros nós de conteúdo.
ImageRenderOptions
for cell in row.GetChildNodes(TableCell):
text = " ".join(rt.Text for rt in cell.GetChildNodes(RichText))Exemplos de Uso
Ler todas as tabelas: travessia completa
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 tabelas para 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 linhas e colunas
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)")Tabelas com imagens nas células
Células podem conter Image nós ao lado ou em vez 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)")Inspecionar tags em uma tabela
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}")Posição no DOM
OutlineElement
└── Table
└── TableRow (0..n)
└── TableCell (0..n)
├── RichText (0..n)
└── Image (0..n)Table é sempre um filho de OutlineElement. Use table.ParentNode para acessar o contêiner OutlineElement.
Veja Também
- RichText: conteúdo de texto dentro das células
- ImageRenderOptions: conteúdo de imagem dentro das células
- Guia do Desenvolvedor de Análise de Tabelas
- Como Analisar Tabelas (KB)
- Blog: Analisar Tabelas do OneNote em Python