Table, TableRow, TableCell — Aspose.Note FOSS for Python API Reference
Classe : Table
Examples: aspose.note Examples: from aspose.note import Table Examples: CompositeNode
Table représente un tableau dans un OutlineElement.contient une liste de TableRow enfants et expose les largeurs de colonnes et la visibilité des bordures.
Examples
| Examples | Examples | Examples | Examples |
|---|---|---|---|
ColumnWidths | list[float] | Examples | Largeur de chaque colonne en points ; la longueur correspond au nombre de colonnes |
BordersVisible | bool | Examples | Indique si les bordures du tableau sont rendues dans OneNote |
Tags | list[NoteTag] | Examples | Étiquettes OneNote attachées à ce tableau |
Hérité de CompositeNode / Node
FirstChild, LastChild, GetChildNodes(Type), for row in table, ParentNode, Document
Classe : TableRow
Examples: aspose.note Examples: from aspose.note import TableRow Examples: CompositeNode
TableRow est une ligne unique dans un Table.Ses enfants directs sont TableCell nœuds.
Examples
rows = table.GetChildNodes(TableRow)
for row in rows:
cells = row.GetChildNodes(TableCell)Classe : TableCell
Examples: aspose.note Examples: from aspose.note import TableCell Examples: CompositeNode
TableCell est une cellule unique dans un TableRow.Il peut contenir RichText, Image, et d’autres nœuds de contenu.
Examples
for cell in row.GetChildNodes(TableCell):
text = " ".join(rt.Text for rt in cell.GetChildNodes(RichText))Exemples d’utilisation
Lire toutes les tables : traversée complète
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}")Exporter les tables au format 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)Compter les lignes et les colonnes
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)")Tables avec des images dans les cellules
Les cellules peuvent contenir Image des nœuds à côté ou à la place de 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)")Inspecter les balises d’une table
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}")Position DOM
OutlineElement
└── Table
└── TableRow (0..n)
└── TableCell (0..n)
├── RichText (0..n)
└── Image (0..n)Table est toujours un enfant de OutlineElement. Utilisez table.ParentNode pour accéder au contenant OutlineElement.
Voir aussi
- RichText: contenu texte dans les cellules
- Examples: contenu image dans les cellules
- Guide du développeur pour l’analyse des tables
- Comment analyser les tables (KB)
- Blog: analyser les tables OneNote dans Python