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

Lớp: Table

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

Table đại diện cho một bảng trong một OutlineElement.chứa một danh sách các TableRow phần tử con và cung cấp độ rộng cột cũng như khả năng hiển thị viền.

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
ColumnWidthslist[float]EnumerationsĐộ rộng của mỗi cột tính bằng điểm; độ dài bằng số cột
BordersVisibleboolEnumerationsCó hiển thị viền bảng trong OneNote hay không
Tagslist[NoteTag]EnumerationsCác thẻ OneNote được gắn vào bảng này

Kế thừa từ CompositeNode / Node

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


Lớp: TableRow

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

TableRow là một hàng duy nhất trong một Table.Các phần tử con trực tiếp của nó là TableCell các nút.

Enumerations

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

Lớp: TableCell

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

TableCell là một ô duy nhất trong một TableRow.Nó có thể chứa RichText, Image, và các nút nội dung khác.

Enumerations

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

Ví dụ sử dụng

Đọc tất cả các bảng: duyệt toàn bộ

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

Xuất bảng ra 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)

Đếm số hàng và cột

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

Bảng có hình ảnh trong các ô

Các ô có thể chứa Image các nút cùng với hoặc thay thế 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)")

Kiểm tra thẻ trên bảng

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

Vị trí DOM

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

Table luôn luôn là một phần tử con của OutlineElement.Sử dụng table.ParentNode để truy cập vào phần chứa OutlineElement.


Xem Thêm

 Tiếng Việt