Table, TableRow, TableCell — Aspose.Note FOSS for Python API Reference
Klasse: Table
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import Table ImageRenderOptions: CompositeNode
Table vertegenwoordigt een tabel binnen een OutlineElement.bevat een lijst van TableRow kinderen en geeft kolombreedtes en randzichtbaarheid weer.
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|---|
ColumnWidths | list[float] | ImageRenderOptions | Breedte van elke kolom in punten; lengte is gelijk aan het aantal kolommen |
BordersVisible | bool | ImageRenderOptions | Of tabelranden worden weergegeven in OneNote |
Tags | list[NoteTag] | ImageRenderOptions | OneNote-tags die aan deze tabel zijn gekoppeld |
Geërfd van CompositeNode / Node
FirstChild, LastChild, GetChildNodes(Type), for row in table, ParentNode, Document
Klasse: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow is een enkele rij binnen een Table.Zijn directe kinderen zijn TableCell knooppunten.
ImageRenderOptions
rows = table.GetChildNodes(TableRow)
for row in rows:
cells = row.GetChildNodes(TableCell)Klasse: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell is een enkele cel binnen een TableRow.Het kan bevatten RichText, Image, en andere inhoudsknooppunten.
ImageRenderOptions
for cell in row.GetChildNodes(TableCell):
text = " ".join(rt.Text for rt in cell.GetChildNodes(RichText))Voorbeelden van gebruik
Lees alle tabellen: volledige traversie
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} cols={len(table.ColumnWidths)} widths={table.ColumnWidths}")
for r_num, row in enumerate(table.GetChildNodes(TableRow), start=1):
cells = row.GetChildNodes(TableCell)
row_data = [
" ".join(rt.Text for rt in cell.GetChildNodes(RichText)).strip()
for cell in cells
]
print(f" Row {r_num}: {row_data}")Exporteer tabellen naar CSV
import csv, io
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("MyNotes.one")
buf = io.StringIO()
writer = csv.writer(buf)
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([])
csv_text = buf.getvalue()
print(csv_text)Tel rijen en kolommen
from aspose.note import Document, Table, TableRow, TableCell
doc = Document("MyNotes.one")
for i, table in enumerate(doc.GetChildNodes(Table), start=1):
rows = table.GetChildNodes(TableRow)
cols = len(rows[0].GetChildNodes(TableCell)) if rows else 0
print(f"Table {i}: {len(rows)} row(s) x {cols} column(s)")Tabellen met afbeeldingen in cellen
Cellen kunnen bevatten Image knooppunten naast of in plaats van 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 = cell.GetChildNodes(RichText)
images = cell.GetChildNodes(Image)
if images:
print(f" Cell with {len(images)} image(s) and {len(texts)} text(s)")Inspecteer tags op een tabel
from aspose.note import Document, Table
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
for tag in table.Tags:
print(f"Table tag: {tag.label!r} completed={tag.completed}")DOM-positie
OutlineElement
└── Table
└── TableRow (0..n)
└── TableCell (0..n)
├── RichText (0..n)
└── Image (0..n)Table is altijd een kind van OutlineElement.Gebruik table.ParentNode om de omvattende te benaderen OutlineElement.
Zie ook
- RichText: tekstinhoud binnen cellen
- ImageRenderOptions: afbeeldingsinhoud binnen cellen
- Handleiding voor ontwikkelaars voor tabelparsing
- Hoe tabellen te parseren (KB)
- Blog: OneNote-tabellen parseren in Python