표 파싱 — Aspose.Note FOSS for Python

OneNote 문서의 표는 3단계 계층 구조로 노출됩니다: Table → TableRow → TableCell. 각 셀은 포함할 수 있습니다 RichText, Image, 및 기타 콘텐츠 노드. 이 페이지에서는 Aspose.Note FOSS가 Python을 위해 지원하는 모든 표 파싱 패턴을 다룹니다.


기본 표 반복

문서의 모든 표를 가져와 셀 텍스트를 읽습니다:

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

doc = Document("MyNotes.one")

for table_num, table in enumerate(doc.GetChildNodes(Table), start=1):
    print(f"\nTable {table_num}: {len(table.Columns)} column(s)")
    for r, row in enumerate(table.GetChildNodes(TableRow), start=1):
        cells = row.GetChildNodes(TableCell)
        values = [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
            for cell in cells
        ]
        print(f"  Row {r}: {values}")

표 속성

속성유형설명
Columnslist[TableColumn]열 정의; 각각 TableColumn 가 있습니다 .Width (float) 및 .LockedWidth (bool)
IsBordersVisiblebool표 테두리가 표시되는지 여부
Tagslist[NoteTag]표에 첨부된 OneNote 태그
from aspose.note import Document, Table

doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
    print(f"Columns: {len(table.Columns)}")
    print(f"Widths (pts): {[col.Width for col in table.Columns]}")
    print(f"Borders visible: {table.IsBordersVisible}")

표를 CSV로 내보내기

표를 CSV 형식으로 변환합니다:

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

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

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([])  # blank line between tables

print(output.getvalue())

페이지별 표 추출

표 추출 범위를 개별 페이지로 제한합니다:

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

doc = Document("MyNotes.one")
for page_num, page in enumerate(doc.GetChildNodes(Page), start=1):
    tables = page.GetChildNodes(Table)
    if not tables:
        continue
    title = (
        page.Title.TitleText.Text
        if page.Title and page.Title.TitleText
        else f"Page {page_num}"
    )
    print(f"\n=== {title} ({len(tables)} table(s)) ===")
    for t, table in enumerate(tables, start=1):
        print(f"  Table {t}:")
        for row in table.GetChildNodes(TableRow):
            cells = row.GetChildNodes(TableCell)
            row_text = [
                " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
                for cell in cells
            ]
            print(f"    {row_text}")

일반 텍스트를 넘어선 셀 콘텐츠

표 셀은 포함할 수 있습니다 Image 및 기타 CompositeNode 함께하는 콘텐츠 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 = [rt.Text for rt in cell.GetChildNodes(RichText) if rt.Text]
            images = cell.GetChildNodes(Image)
            print(f"  Cell texts: {texts}  images: {len(images)}")

표 개수 및 요약

문서의 모든 표에 대한 통계를 수집합니다:

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

doc = Document("MyNotes.one")
tables = doc.GetChildNodes(Table)
print(f"Total tables: {len(tables)}")

for i, table in enumerate(tables, start=1):
    rows = table.GetChildNodes(TableRow)
    if rows:
        cols = len(rows[0].GetChildNodes(TableCell))
    else:
        cols = 0
    print(f"  Table {i}: {len(rows)} row(s) x {cols} column(s)  widths={[col.Width for col in table.Columns]}")

표의 태그 검사

표는 지원합니다 NoteTag 항목을 직접:

from aspose.note import Document, Table, TagStatus

doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
    for tag in table.Tags:
        is_completed = tag.Status == TagStatus.Completed
        print(f"Table tag: {tag.Label}  icon={tag.Icon}  completed={is_completed}")

테이블의 DOM 위치

테이블은 다음의 자식으로 표시됩니다 OutlineElement 노드 내에 Outline 각 컨테이너에 Page. 계층 구조는 다음과 같습니다:

Page
  └── Outline
        └── OutlineElement
              └── Table
                    └── TableRow
                          └── TableCell
                                └── RichText / Image

테이블에 접근하려면 다음을 통해서도 할 수 있습니다 GetChildNodes(Table) 어떤 상위 노드 레벨에서도, 전체 서브트리를 검색합니다.


  • table.Columns 은(는) 목록입니다 TableColumn 객체; 사용 [col.Width for col in table.Columns] 포인트 단위의 열 너비를 가져옵니다. 길이는 열 수와 같습니다.
  • 셀 내용이 항상 순수하게 RichText; 항상 확인하십시오 Image 노드도 전체 정확성이 중요할 경우.
  • 사용 table.GetChildNodes(TableRow) 반복하는 대신 for row in table 제네릭 반복자 대신 타입이 지정된 리스트가 필요하다면.
  • IsBordersVisible 저장 시 OneNote 사용자의 표시 기본 설정을 반영합니다; 콘텐츠 추출에는 영향을 주지 않습니다.

또 보기

 한국어