TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Clasa: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow reprezintă un rând unic într-un Table. Copiii săi direcți sunt TableCell noduri.
ImageRenderOptions
TableRow nu are proprietăți în afara celor moștenite de la CompositeNode și Node.
Moștenit de la CompositeNode
| Proprietate / Metodă | ImageRenderOptions |
|---|---|
FirstChild | Primul copil direct TableCell, sau None |
LastChild | Ultimul copil direct TableCell, sau None |
AppendChildLast(node) | Adaugă un TableCell |
AppendChildFirst(node) | Adaugă la început un TableCell |
InsertChild(index, node) | Inserează un TableCell la o poziție specifică |
RemoveChild(node) | Elimină un TableCell |
GetChildNodes(Type) | Căutare recursivă în adâncime |
for cell in row | Iterează direct TableCell copii |
Moștenit de la Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Cel care conține Table |
Document | Rădăcina Document |
Clasa: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell reprezintă o singură celulă într-un TableRow. Poate conține RichText, Image, și alte noduri de conținut ca și copii.
ImageRenderOptions
TableCell nu are proprietăți în afara celor moștenite de la CompositeNode și Node.
Moștenit de la CompositeNode
| Proprietate / Metodă | ImageRenderOptions |
|---|---|
FirstChild | Primul copil de conținut direct |
LastChild | Ultimul copil de conținut direct |
AppendChildLast(node) | Adaugă un nod de conținut la această celulă |
AppendChildFirst(node) | Adaugă un nod de conținut la început |
InsertChild(index, node) | Inserează la o poziție specifică |
RemoveChild(node) | Elimină un nod de conținut |
GetChildNodes(Type) | Căutare recursivă depth-first |
for child in cell | Iterați copiii direcți |
Moștenit de la Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Cel care conține TableRow |
Document | Rădăcina Document |
Exemple de utilizare
Iterați toate rândurile și celulele tabelului
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), "|")Extrageți textul din fiecare celulă ca o listă plată
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)Construiți un tabel programatic
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)Numărați rândurile și celulele
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)}")Siguranță None
TableRow și TableCell nu au proprietăți proprii care pot fi nule. Listele de copii returnate de GetChildNodes sunt întotdeauna liste (pot fi goale).
Vezi și
- ImageRenderOptions: părinte al TableRow
- RichText: conținut principal în interiorul TableCell
- ImageRenderOptions: conținut imagine în interiorul TableCell
- CompositeNode: metode moștenite de gestionare a copiilor