TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Class: TableRow
Package: aspose.note
Import: from aspose.note import TableRow
Inherits: CompositeNode
TableRow represents a single row within a Table. Its direct children are TableCell nodes.
Properties
TableRow has no properties beyond those inherited from CompositeNode and Node.
Inherited from CompositeNode
| Property / Method | Description |
|---|---|
FirstChild | First direct child TableCell, or None |
LastChild | Last direct child TableCell, or None |
AppendChildLast(node) | Append a TableCell |
AppendChildFirst(node) | Prepend a TableCell |
InsertChild(index, node) | Insert a TableCell at a specific position |
RemoveChild(node) | Remove a TableCell |
GetChildNodes(Type) | Recursive depth-first search |
for cell in row | Iterate direct TableCell children |
Inherited from Node
| Property | Description |
|---|---|
ParentNode | The containing Table |
Document | The root Document |
Class: TableCell
Package: aspose.note
Import: from aspose.note import TableCell
Inherits: CompositeNode
TableCell represents a single cell within a TableRow. It can contain RichText, Image, and other content nodes as children.
Properties
TableCell has no properties beyond those inherited from CompositeNode and Node.
Inherited from CompositeNode
| Property / Method | Description |
|---|---|
FirstChild | First direct content child |
LastChild | Last direct content child |
AppendChildLast(node) | Append a content node to this cell |
AppendChildFirst(node) | Prepend a content node |
InsertChild(index, node) | Insert at a specific position |
RemoveChild(node) | Remove a content node |
GetChildNodes(Type) | Recursive depth-first search |
for child in cell | Iterate direct children |
Inherited from Node
| Property | Description |
|---|---|
ParentNode | The containing TableRow |
Document | The root Document |
Usage Examples
Iterate all table rows and cells
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
print(f"Table columns: {table.ColumnWidths}")
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), "|")Extract text from every cell as a flat list
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)Build a table programmatically
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())
table = elem.AppendChildLast(Table())
table.BordersVisible = True
table.ColumnWidths = [100.0, 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)Count rows and cells
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)}")None-Safety
TableRow and TableCell have no nullable own properties. The child lists returned by GetChildNodes are always lists (may be empty).
See Also
- Table: parent of TableRow
- RichText: primary content within TableCell
- Image: image content within TableCell
- CompositeNode: inherited child management methods