TableRow / TableCell

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

Klase: TableRow

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

TableRow pārstāv vienu rindu iekš Table. Tās tiešās bērni ir TableCell mezgli.


ImageRenderOptions

TableRow nav īpašību, izņemot tās, kas mantotas no CompositeNode un Node.

Manto no CompositeNode

Īpašība / MetodeImageRenderOptions
FirstChildPirmais tiešais bērns TableCell, vai None
LastChildPēdējais tiešais bērns TableCell, vai None
AppendChildLast(node)Pievienot TableCell
AppendChildFirst(node)Pievienot sākumā TableCell
InsertChild(index, node)Ievietot TableCell konkrētā pozīcijā
RemoveChild(node)Noņemt TableCell
GetChildNodes(Type)Rekursīva dziļuma pirmā meklēšana
for cell in rowIterēt tieši TableCell bērni

Manto no Node

ImageRenderOptionsImageRenderOptions
ParentNodeSaturošais Table
DocumentSakne Document

Klase: TableCell

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

TableCell pārstāv vienu šūnu iekš TableRow.Tā var saturēt RichText, Image, un citus satura mezglus kā bērnus.


ImageRenderOptions

TableCell nav īpašību, izņemot tās, kas mantotas no CompositeNode un Node.

Manto no CompositeNode

Īpašība / MetodeImageRenderOptions
FirstChildPirmais tiešais satura bērns
LastChildPēdējais tiešais satura bērns
AppendChildLast(node)Pievienot satura mezglu šai šūnai
AppendChildFirst(node)Pievienot satura mezglu sākumā
InsertChild(index, node)Ievietot konkrētā pozīcijā
RemoveChild(node)Noņemt satura mezglu
GetChildNodes(Type)Rekursīva dziļuma pirmā meklēšana
for child in cellIterēt tiešos bērnus

Manto no Node

ImageRenderOptionsImageRenderOptions
ParentNodeSaturošais TableRow
DocumentSakne Document

Lietošanas piemēri

Iterēt visas tabulas rindas un šūnas

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

Izgūt tekstu no katras šūnas kā plakanu sarakstu

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)

Izveidot tabulu programmatiski

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)

Skaitīt rindas un šūnas

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 drošība

TableRow un TableCell nav nullējamu pašīgo īpašību. Bērnu saraksti, ko atgriež GetChildNodes vienmēr ir saraksti (var būt tukši).


Skatīt arī

 Latviešu