TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Klasa: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow reprezentuje pojedynczy wiersz w Table. Jego bezpośrednie elementy potomne to TableCell węzły.
ImageRenderOptions
TableRow nie ma właściwości poza tymi odziedziczonymi po CompositeNode i Node.
Dziedziczone z CompositeNode
| Właściwość / Metoda | ImageRenderOptions |
|---|---|
FirstChild | Pierwszy bezpośredni element potomny TableCell, lub None |
LastChild | Ostatni bezpośredni element potomny TableCell, lub None |
AppendChildLast(node) | Dodaj TableCell |
AppendChildFirst(node) | Dodaj na początek TableCell |
InsertChild(index, node) | Wstaw TableCell w określonej pozycji |
RemoveChild(node) | Usuń TableCell |
GetChildNodes(Type) | Rekurencyjne przeszukiwanie w głąb |
for cell in row | Iteruj bezpośrednio TableCell dzieci |
Dziedziczone po Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Zawierający Table |
Document | Korzeń Document |
Klasa: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell reprezentuje pojedynczą komórkę w TableRow. Może zawierać RichText, Image, oraz inne węzły treści jako dzieci.
ImageRenderOptions
TableCell nie ma właściwości poza tymi odziedziczonymi po CompositeNode i Node.
Dziedziczone z CompositeNode
| Właściwość / Metoda | ImageRenderOptions |
|---|---|
FirstChild | Pierwszy bezpośredni element treści |
LastChild | Ostatni bezpośredni element treści |
AppendChildLast(node) | Dołącz węzeł treści do tej komórki |
AppendChildFirst(node) | Wstaw węzeł treści na początek |
InsertChild(index, node) | Wstaw w określonej pozycji |
RemoveChild(node) | Usuń węzeł treści |
GetChildNodes(Type) | Rekurencyjne przeszukiwanie w głąb |
for child in cell | Iteruj bezpośrednie elementy potomne |
Dziedziczone po Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Zawierający TableRow |
Document | Korzeń Document |
Przykłady użycia
Iteruj wszystkie wiersze i komórki tabeli
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), "|")Wyodrębnij tekst z każdej komórki jako płaską 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)Zbuduj tabelę programowo
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)Policz wiersze i komórki
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)}")Bezpieczeństwo przy None
TableRow i TableCell nie mają własnych właściwości dopuszczających wartość null. Listy dzieci zwracane przez GetChildNodes zawsze są listami (mogą być puste).
Zobacz także
- ImageRenderOptions: rodzic TableRow
- RichText: główna zawartość w TableCell
- ImageRenderOptions: zawartość obrazu w TableCell
- CompositeNode: odziedziczone metody zarządzania dziećmi