Tablo Ayrıştırma — Aspose.Note FOSS for Python

OneNote belgelerindeki tablolar üç seviyeli bir hiyerarşi olarak sunulur: Table → TableRow → TableCell. Her hücre şunları içerebilir RichText, Image, ve diğer içerik düğümleri. Bu sayfa, Aspose.Note FOSS tarafından Python için desteklenen tüm tablo ayrıştırma desenlerini kapsar.


Temel Tablo İterasyonu

Belgedeki tüm tabloları alın ve hücre metinlerini okuyun:

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

Tablo Özellikleri

ÖzellikTürAçıklama
Columnslist[TableColumn]Sütun tanımları; her biri TableColumn sahiptir .Width (float) ve .LockedWidth (bool)
IsBordersVisibleboolTablo kenarlıklarının gösterilip gösterilmediği
Tagslist[NoteTag]Tabloya eklenmiş OneNote etiketleri
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}")

Tabloyu CSV’ye Dışa Aktar

Bir tabloyu CSV formatına dönüştürün:

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

Sayfa Başına Tabloları Çıkar

Tablo çıkarımını bireysel sayfalara sınırlayın:

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

Düz Metnin Ötesindeki Hücre İçeriği

Tablo hücreleri şunları içerebilir Image ve diğer CompositeNode içerik yan yana 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)}")

Tabloları Say ve Özetle

Bir belgedeki tüm tablolar hakkında istatistik toplayın:

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

Tablolardaki Etiketleri İncele

Tablolar şunları destekler NoteTag öğeler doğrudan:

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

Tabloların DOM Konumu

Tablolar, …’nin çocukları olarak görünür OutlineElement düğümler içinde Outline her birindeki kapsayıcılar Page. Hiyerarşi şudur:

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

Tablolara ayrıca şu şekilde ulaşabilirsiniz GetChildNodes(Table) herhangi bir üst düğüm seviyesinde, ve tam alt ağacı arar.


İpuçları

  • table.Columns bir listedir TableColumn nesneler; kullan [col.Width for col in table.Columns] sütun genişliklerini puan cinsinden almak için. Uzunluk, sütun sayısına eşittir.
  • Hücre içeriği her zaman tamamen RichText; her zaman kontrol edin Image tam doğruluk önemliyse düğümleri de.
  • Kullan table.GetChildNodes(TableRow) yinelemek yerine for row in table eğer tiplenmiş bir listeye ihtiyacınız varsa, genel bir yineleyici yerine.
  • IsBordersVisible kaydetme sırasında OneNote kullanıcısının görüntüleme tercihini yansıtır; içerik çıkarımını etkilemez.

Ayrıca Bakınız

 Türkçe