टेबल पार्सिंग — Aspose.Note FOSS for Python

OneNote दस्तावेज़ों में तालिकाएँ तीन-स्तरीय पदानुक्रम के रूप में प्रदर्शित होती हैं: 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 उपयोगकर्ता की डिस्प्ले प्राथमिकता को दर्शाता है; यह सामग्री निष्कर्षण को प्रभावित नहीं करता।.

संबंधित देखें

 हिन्दी