TableRow / TableCell

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ść / MetodaImageRenderOptions
FirstChildPierwszy bezpośredni element potomny TableCell, lub None
LastChildOstatni 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 rowIteruj bezpośrednio TableCell dzieci

Dziedziczone po Node

ImageRenderOptionsImageRenderOptions
ParentNodeZawierający Table
DocumentKorzeń 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ść / MetodaImageRenderOptions
FirstChildPierwszy bezpośredni element treści
LastChildOstatni 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 cellIteruj bezpośrednie elementy potomne

Dziedziczone po Node

ImageRenderOptionsImageRenderOptions
ParentNodeZawierający TableRow
DocumentKorzeń 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

 Polski