TableRow / TableCell

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

Klasė: TableRow

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

TableRow reprezintuoja vieną eilutę Table. Jo tiesioginiai vaikai yra TableCell mazgai.


ImageRenderOptions

TableRow neturi savybių, išskyrus tas, kurios paveldimos iš CompositeNode ir Node.

Paveldėta iš CompositeNode

Savybė / MetodasImageRenderOptions
FirstChildPirmas tiesioginis vaikas TableCell, arba None
LastChildPaskutinis tiesioginis vaikas TableCell, arba None
AppendChildLast(node)Pridėti TableCell
AppendChildFirst(node)Pridėti į pradžią TableCell
InsertChild(index, node)Įterpti TableCell konkrečioje pozicijoje
RemoveChild(node)Pašalinti TableCell
GetChildNodes(Type)Rekursinė gylio pirmumo paieška
for cell in rowIteruoti tiesiogiai TableCell vaikai

Paveldėta iš Node

ImageRenderOptionsImageRenderOptions
ParentNodeTurintis Table
DocumentŠaknis Document

Klasė: TableCell

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

TableCell žymi vieną langelį, esantį TableRow.Gali turėti RichText, Image, ir kitus turinio mazgus kaip vaikus.


ImageRenderOptions

TableCell neturi jokių savybių, išskyrus tas, kurios paveldimos iš CompositeNode ir Node.

Paveldėta iš CompositeNode

Savybė / MetodasImageRenderOptions
FirstChildPirmas tiesioginis turinio vaikas
LastChildPaskutinis tiesioginis turinio vaikas
AppendChildLast(node)Pridėti turinio mazgą prie šio langelio
AppendChildFirst(node)Įdėti turinio mazgą į pradžią
InsertChild(index, node)Įterpti į konkrečią poziciją
RemoveChild(node)Pašalinti turinio mazgą
GetChildNodes(Type)Rekursinė gylio pirmumo paieška
for child in cellIteruoti tiesioginius vaikus

Paveldėta iš Node

ImageRenderOptionsImageRenderOptions
ParentNodeKonteineris TableRow
DocumentŠaknis Document

Naudojimo pavyzdžiai

Iteruokite visas lentelės eilutes ir langelius

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

Išskirkite tekstą iš kiekvieno langelio kaip plokščią sąrašą

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)

Sukurkite lentelę programiškai

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)

Suskaičiuokite eilutes ir langelius

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-saugumas

TableRow ir TableCell neturi nullable savų savybių. Vaikų sąrašai, grąžinami pagal GetChildNodes visada yra sąrašai (gali būti tušti).


Žr. taip pat

 Lietuvių