TableRow / TableCell

TableRow / TableCell — Aspose.Note FOSS for Python API Reference

Trieda: TableRow

ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode

TableRow predstavuje jeden riadok v Table. Jeho priame deti sú TableCell uzly.


ImageRenderOptions

TableRow nemá žiadne vlastnosti okrem tých, ktoré dedí od CompositeNode a Node.

Zdedené z CompositeNode

Vlastnosť / MetódaImageRenderOptions
FirstChildPrvý priamy potomok TableCell, alebo None
LastChildPosledný priamy potomok TableCell, alebo None
AppendChildLast(node)Pridať TableCell
AppendChildFirst(node)Pridať na začiatok TableCell
InsertChild(index, node)Vložiť TableCell na konkrétnu pozíciu
RemoveChild(node)Odstrániť TableCell
GetChildNodes(Type)Rekurzívne hľadanie do hĺbky
for cell in rowIterovať priamo TableCell deti

Zdedené z Node

ImageRenderOptionsImageRenderOptions
ParentNodeObsahujúci Table
DocumentKoreň Document

Trieda: TableCell

ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode

TableCell predstavuje jednu bunku v TableRow.Môže obsahovať RichText, Image, a ďalšie uzly obsahu ako deti.


ImageRenderOptions

TableCell nemá žiadne vlastnosti okrem tých zdedených z CompositeNode a Node.

Zdedené z CompositeNode

Vlastnosť / MetódaImageRenderOptions
FirstChildPrvé priame dieťa obsahu
LastChildPosledné priame dieťa obsahu
AppendChildLast(node)Pripojiť uzol obsahu k tejto bunke
AppendChildFirst(node)Vložiť uzol obsahu na začiatok
InsertChild(index, node)Vložiť na konkrétnu pozíciu
RemoveChild(node)Odstrániť uzol obsahu
GetChildNodes(Type)Rekurzívne hľadanie do hĺbky
for child in cellIterovať priame deti

Zdedené z Node

ImageRenderOptionsImageRenderOptions
ParentNodeObsahujúci TableRow
DocumentKoreň Document

Príklady použitia

Iterovať všetky riadky a bunky tabuľky

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), "|")

Extrahovať text z každej bunky ako plochý zoznam

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)

Vytvoriť tabuľku programovo

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)

Počítať riadky a bunky

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)}")

Bezpečnosť pri None

TableRow a TableCell nemajú žiadne nullable vlastné vlastnosti. Zoznamy potomkov vrátené GetChildNodes sú vždy zoznamy (môžu byť prázdne).


Pozri tiež

 Slovenčina