TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Classe: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow representa uma única linha dentro de um Table. Seus filhos diretos são TableCell nós.
ImageRenderOptions
TableRow não tem propriedades além daquelas herdadas de CompositeNode e Node.
Herda de CompositeNode
| Propriedade / Método | ImageRenderOptions |
|---|---|
FirstChild | Primeiro filho direto TableCell, ou None |
LastChild | Último filho direto TableCell, ou None |
AppendChildLast(node) | Anexar um TableCell |
AppendChildFirst(node) | Adicionar no início um TableCell |
InsertChild(index, node) | Inserir um TableCell em uma posição específica |
RemoveChild(node) | Remover um TableCell |
GetChildNodes(Type) | Busca em profundidade recursiva |
for cell in row | Iterar diretamente TableCell filhos |
Herda de Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | O contido Table |
Document | A raiz Document |
Classe: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell representa uma única célula dentro de um TableRow. Pode conter RichText, Image, e outros nós de conteúdo como filhos.
ImageRenderOptions
TableCell não tem propriedades além daquelas herdadas de CompositeNode e Node.
Herda de CompositeNode
| Propriedade / Método | ImageRenderOptions |
|---|---|
FirstChild | Primeiro filho de conteúdo direto |
LastChild | Último filho de conteúdo direto |
AppendChildLast(node) | Anexar um nó de conteúdo a esta célula |
AppendChildFirst(node) | Adicionar um nó de conteúdo no início |
InsertChild(index, node) | Inserir em uma posição específica |
RemoveChild(node) | Remover um nó de conteúdo |
GetChildNodes(Type) | Busca em profundidade recursiva |
for child in cell | Iterar filhos diretos |
Herda de Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | O contêiner TableRow |
Document | A raiz Document |
Exemplos de Uso
Iterar todas as linhas e células da tabela
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), "|")Extrair texto de cada célula como uma 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 uma tabela programaticamente
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 linhas e células
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)}")Segurança contra None
TableRow e TableCell não têm propriedades próprias anuláveis. As listas de filhos retornadas por GetChildNodes são sempre listas (podem estar vazias).
Veja Também
- ImageRenderOptions: pai de TableRow
- RichText: conteúdo principal dentro de TableCell
- ImageRenderOptions: conteúdo de imagem dentro de TableCell
- CompositeNode: métodos herdados de gerenciamento de filhos