Table, TableRow, TableCell — Aspose.Note FOSS for Python API Reference

クラス: Table

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

Table は、…内のテーブルを表します OutlineElement.は、…のリストを保持します TableRow 子要素を保持し、列幅と罫線の表示を公開します。.

ImageRenderOptions

ImageRenderOptionsImageRenderOptionsImageRenderOptionsImageRenderOptions
ColumnWidthslist[float]ImageRenderOptions各列の幅(ポイント単位)。長さは列数と同じです。
BordersVisibleboolImageRenderOptionsOneNote でテーブルの罫線が描画されるかどうか
Tagslist[NoteTag]ImageRenderOptionsこのテーブルに付随する OneNote タグ

CompositeNode / Node から継承

FirstChild, LastChild, GetChildNodes(Type), for row in table, ParentNode, Document


クラス: TableRow

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

TableRow は、…内の単一の行です Table.その直接の子要素は TableCell ノードです。.

ImageRenderOptions

rows = table.GetChildNodes(TableRow)
for row in rows:
    cells = row.GetChildNodes(TableCell)

クラス: TableCell

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

TableCell は、…内の単一のセルです TableRow.それは含めることができます RichText, Image,、および他のコンテンツノード。.

ImageRenderOptions

for cell in row.GetChildNodes(TableCell):
    text = " ".join(rt.Text for rt in cell.GetChildNodes(RichText))

使用例

すべてのテーブルを読み取る: 完全走査

from aspose.note import Document, Table, TableRow, TableCell, RichText

doc = Document("MyNotes.one")
for t_num, table in enumerate(doc.GetChildNodes(Table), start=1):
    print(f"\nTable {t_num}  cols={len(table.ColumnWidths)}  widths={table.ColumnWidths}")
    for r_num, row in enumerate(table.GetChildNodes(TableRow), start=1):
        cells = row.GetChildNodes(TableCell)
        row_data = [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
            for cell in cells
        ]
        print(f"  Row {r_num}: {row_data}")

テーブルを CSV にエクスポート

import csv, io
from aspose.note import Document, Table, TableRow, TableCell, RichText

doc = Document("MyNotes.one")
buf = io.StringIO()
writer = csv.writer(buf)

for table in doc.GetChildNodes(Table):
    for row in table.GetChildNodes(TableRow):
        values = [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
            for cell in row.GetChildNodes(TableCell)
        ]
        writer.writerow(values)
    writer.writerow([])

csv_text = buf.getvalue()
print(csv_text)

行数と列数をカウント

from aspose.note import Document, Table, TableRow, TableCell

doc = Document("MyNotes.one")
for i, table in enumerate(doc.GetChildNodes(Table), start=1):
    rows = table.GetChildNodes(TableRow)
    cols = len(rows[0].GetChildNodes(TableCell)) if rows else 0
    print(f"Table {i}: {len(rows)} row(s) x {cols} column(s)")

セルに画像が含まれるテーブル

セルは含むことができます Image ノードを横に並べて、または代わりに RichText:

from aspose.note import Document, Table, TableRow, TableCell, RichText, Image

doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
    for row in table.GetChildNodes(TableRow):
        for cell in row.GetChildNodes(TableCell):
            texts = cell.GetChildNodes(RichText)
            images = cell.GetChildNodes(Image)
            if images:
                print(f"  Cell with {len(images)} image(s) and {len(texts)} text(s)")

テーブルのタグを検査

from aspose.note import Document, Table

doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
    for tag in table.Tags:
        print(f"Table tag: {tag.label!r}  completed={tag.completed}")

DOM 位置

OutlineElement
  └── Table
        └── TableRow (0..n)
              └── TableCell (0..n)
                    ├── RichText (0..n)
                    └── Image (0..n)

Table は常に子です OutlineElement.。使用 table.ParentNode を使用して、包含するものにアクセスするために OutlineElement.


関連項目

 日本語