TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Třída: TableRow
Properties: aspose.note Properties: from aspose.note import TableRow Properties: CompositeNode
TableRow představuje jeden řádek v Table. Jeho přímé potomky jsou TableCell uzly.
Properties
TableRow nemá žádné vlastnosti nad rámec těch, které dědí z CompositeNode a Node.
Děděno z CompositeNode
| Vlastnost / Metoda | Properties |
|---|---|
FirstChild | První přímý potomek TableCell, nebo None |
LastChild | Poslední přímý potomek TableCell, nebo None |
AppendChildLast(node) | Přidat TableCell |
AppendChildFirst(node) | Přidat na začátek TableCell |
InsertChild(index, node) | Vložit TableCell na konkrétní pozici |
RemoveChild(node) | Odebrat TableCell |
GetChildNodes(Type) | Rekurzivní prohledávání do hloubky |
for cell in row | Iterovat přímo TableCell potomci |
Děděno z Node
| Properties | Properties |
|---|---|
ParentNode | Obsahující Table |
Document | Kořen Document |
Třída: TableCell
Properties: aspose.note Properties: from aspose.note import TableCell Properties: CompositeNode
TableCell představuje jedinou buňku v TableRow. Může obsahovat RichText, Image, a další uzly obsahu jako potomky.
Properties
TableCell nemá žádné vlastnosti nad rámec těch zděděných z CompositeNode a Node.
Děděno z CompositeNode
| Vlastnost / Metoda | Properties |
|---|---|
FirstChild | První přímý obsahový potomek |
LastChild | Poslední přímý obsahový potomek |
AppendChildLast(node) | Připojit uzel obsahu k této buňce |
AppendChildFirst(node) | Přidat uzel obsahu na začátek |
InsertChild(index, node) | Vložit na konkrétní pozici |
RemoveChild(node) | Odebrat uzel obsahu |
GetChildNodes(Type) | Rekurzivní prohledávání do hloubky |
for child in cell | Procházet přímé potomky |
Děděno z Node
| Properties | Properties |
|---|---|
ParentNode | Obsahující TableRow |
Document | Kořen Document |
Příklady použití
Procházet všechny řádky a buňky tabulky
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), "|")Extrahovat text z každé buňky jako plochý seznam
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)Vytvořit tabulku programově
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)Spočítat řádky a buňky
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 a TableCell nemají žádné nullable vlastní vlastnosti. Dětské seznamy vrácené metodou GetChildNodes jsou vždy seznamy (mohou být prázdné).
Viz také
- Properties: rodič TableRow
- RichText: primární obsah v TableCell
- Properties: obsah obrázku v TableCell
- CompositeNode: zděděné metody správy potomků