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 は継承元から受け継いだもの以外にプロパティがありません CompositeNodeNode.

CompositeNode から継承

プロパティ / メソッドImageRenderOptions
FirstChild最初の直接の子 TableCell,、または None
LastChild最後の直接の子 TableCell,、または None
AppendChildLast(node)追加する TableCell
AppendChildFirst(node)先頭に追加 TableCell
InsertChild(index, node)挿入 TableCell 特定の位置に
RemoveChild(node)削除 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 nullable な所有プロパティがありません。返される子リストは GetChildNodes 常にリストです(空の場合もあります)。.


関連項目

 日本語