TableRow / TableCell

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

מחלקה: TableRow

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

TableRow מייצג שורה בודדת בתוך Table. הצאצאים הישירים שלו הם TableCell צמתים.


ImageRenderOptions

TableRow אין לו תכונות מעבר לאלה שהורשו מ CompositeNode ו Node.

ירש מ-CompositeNode

מאפיין / שיטהImageRenderOptions
FirstChildהצאצא הישיר הראשון TableCell, או None
LastChildהצאצא הישיר האחרון TableCell, או None
AppendChildLast(node)הוסף a TableCell
AppendChildFirst(node)הוסף לפני a TableCell
InsertChild(index, node)הכנס a TableCell במיקום ספציפי
RemoveChild(node)הסר a TableCell
GetChildNodes(Type)חיפוש עומק ראשון רקורסיבי
for cell in rowחזור ישירות TableCell צאצאים

יורש מ-Node

ImageRenderOptionsImageRenderOptions
ParentNodeהמכיל Table
Documentהשורש Document

מחלקה: TableCell

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

TableCell מייצג תא יחיד בתוך TableRow. הוא יכול להכיל RichText, Image, ואלמנטים של תוכן אחרים כילדים.


ImageRenderOptions

TableCell אין לו תכונות מעבר לאלה שהורשו מ CompositeNode ו Node.

ירש מ-CompositeNode

תכונה / שיטהImageRenderOptions
FirstChildהילד הישיר הראשון של תוכן
LastChildהילד הישיר האחרון של תוכן
AppendChildLast(node)הוסף צומת תוכן לתא זה
AppendChildFirst(node)הוסף צומת תוכן בתחילת
InsertChild(index, node)הכנס במיקום ספציפי
RemoveChild(node)הסר צומת תוכן
GetChildNodes(Type)חיפוש רקורסיבי בעומק ראשון
for child in cellעבור על הילדים הישירים

יורש מ-Node

ImageRenderOptionsImageRenderOptions
ParentNodeהקונטיינר TableRow
Documentהשורש Document

דוגמאות שימוש

עבור על כל השורות והתאים בטבלה

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

הוצא טקסט מכל תא כרשימה שטוחה

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)

בנה טבלה באופן תכנותי

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)

ספור שורות ותאים

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

TableRow ו TableCell אין להם תכונות משלויות ניתנות לאפס. רשימות הילדים המוחזרות על ידי GetChildNodes תמיד רשימות (ייתכן ריקות).


ראה גם

 עברית