تداول الخيارات الثنائية - Aspose.Note FOSS for Python

يتم عرض اللوحات في مستندات OneNote على أنها سلسلة من المستويات الثلاث: Table → TableRow → TableCell.يمكن لكل خلية أن تحتوي على RichText, Image,هذه الصفحة تغطي كل نموذج تقسيم الجدول مدعوم من Aspose.Note FOSS for 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 (السفينة) و .LockedWidth ( بوتين )
IsBordersVisibleboolهل تظهر حدود الطاولة
Tagslist[NoteTag]OneNote Tags المرفقة إلى الجدول
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}")

موقع اللوحات

يظهر الكتب كأطفال 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 في الوقت المناسب؛ فإنه لا يؤثر على استخراج المحتوى.

انظر أيضا

 العربية