Python में OneNote तालिकाओं को पार्स करें

Microsoft OneNote उपयोगकर्ताओं को पृष्ठों में सीधे संरचित तालिकाएँ एम्बेड करने देता है, जो कार्य सूचियों, समय‑सारिणियों, तुलना मैट्रिक्स और डेटा संग्रह फ़ॉर्म के लिए उपयुक्त हैं। Aspose.Note FOSS for Python इसे प्रोग्रामेटिक रूप से इस सभी तालिका डेटा को निकालना संभव बनाता है, बिना Microsoft Office इंस्टॉलेशन की आवश्यकता के।.

इंस्टॉल करें

pip install aspose-note

दस्तावेज़ लोड करें और तालिकाएँ खोजें

GetChildNodes(Table) पूरे दस्तावेज़ में पुनरावर्ती खोज करता है और प्रत्येक तालिका को एक के रूप में लौटाता है Table ऑब्जेक्ट:

from aspose.note import Document, Table

doc = Document("MyNotes.one")
tables = doc.GetChildNodes(Table)
print(f"Found {len(tables)} table(s)")

सेल मान पढ़ें

तालिकाएँ तीन-स्तरीय पदानुक्रम का पालन करती हैं: Table → TableRow → TableCell. प्रत्येक सेल में होता है RichText नोड्स जिनके .Text सादा-टेक्स्ट सामग्री देता है:

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}:")
    for r_num, row in enumerate(table.GetChildNodes(TableRow), start=1):
        cells = row.GetChildNodes(TableCell)
        row_values = [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
            for cell in cells
        ]
        print(f"  Row {r_num}: {row_values}")

कॉलम चौड़ाइयों की जाँच करें

Table.ColumnWidths प्रत्येक कॉलम की संग्रहीत चौड़ाई को पॉइंट्स में लौटाता है:

from aspose.note import Document, Table

doc = Document("MyNotes.one")
for i, table in enumerate(doc.GetChildNodes(Table), start=1):
    print(f"Table {i}: {len(table.ColumnWidths)} column(s)")
    print(f"  Widths (pts): {table.ColumnWidths}")
    print(f"  Borders visible: {table.BordersVisible}")

सभी तालिकाओं को CSV में निर्यात करें

दस्तावेज़ में प्रत्येक तालिका को CSV फ़ॉर्मेट में बदलें:

import csv, 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 row between tables

with open("tables.csv", "w", encoding="utf-8", newline="") as f:
    f.write(output.getvalue())

print("Saved tables.csv")

तालिकाओं को Python डिक्ट / JSON में निर्यात करें

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

doc = Document("MyNotes.one")
result = []

for table in doc.GetChildNodes(Table):
    rows = []
    for row in table.GetChildNodes(TableRow):
        cells = [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
            for cell in row.GetChildNodes(TableCell)
        ]
        rows.append(cells)
    result.append({"rows": rows, "column_widths": table.ColumnWidths})

print(json.dumps(result, indent=2))

पहली पंक्ति को हेडर के रूप में उपयोग करें

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

doc = Document("MyNotes.one")

for table in doc.GetChildNodes(Table):
    rows = table.GetChildNodes(TableRow)
    if not rows:
        continue

    def row_text(row):
        return [
            " ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
            for cell in row.GetChildNodes(TableCell)
        ]

    headers = row_text(rows[0])
    print("Headers:", headers)
    for row in rows[1:]:
        record = dict(zip(headers, row_text(row)))
        print("  Record:", record)

लाइब्रेरी तालिकाओं के लिए क्या समर्थन देती है

फ़ीचरसमर्थित
Table.ColumnWidthsहाँ: कॉलम चौड़ाई पॉइंट्स में
Table.BordersVisibleहाँ
Table.Tagsहाँ: OneNote टैग टेबल्स पर
सेल टेक्स्ट के माध्यम से RichTextहाँ
सेल छवियों के माध्यम से Imageहाँ
मर्ज्ड सेल्स (rowspan/colspan मेटाडाटा)सार्वजनिक API में उजागर नहीं
टेबल्स लिखें/संपादित करें और सहेजें .oneनहीं

आगे के कदम