TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Classe : TableRow
Examples: aspose.note Examples: from aspose.note import TableRow Examples: CompositeNode
TableRow représente une ligne unique au sein d’un Table. Ses enfants directs sont TableCell nœuds.
Examples
TableRow n’a aucune propriété au-delà de celles héritées de CompositeNode et Node.
Hérité de CompositeNode
| Propriété / Méthode | Examples |
|---|---|
FirstChild | Premier enfant direct TableCell, ou None |
LastChild | Dernier enfant direct TableCell, ou None |
AppendChildLast(node) | Ajouter un TableCell |
AppendChildFirst(node) | Préfixer un TableCell |
InsertChild(index, node) | Insérer un TableCell à une position spécifique |
RemoveChild(node) | Supprimer un TableCell |
GetChildNodes(Type) | Recherche en profondeur récursive |
for cell in row | Itérer directement TableCell enfants |
Hérité de Node
| Examples | Examples |
|---|---|
ParentNode | Le contenant Table |
Document | La racine Document |
Classe : TableCell
Examples: aspose.note Examples: from aspose.note import TableCell Examples: CompositeNode
TableCell représente une cellule unique au sein d’un TableRow. Il peut contenir RichText, Image, et d’autres nœuds de contenu comme enfants.
Examples
TableCell n’a aucune propriété au-delà de celles héritées de CompositeNode et Node.
Hérité de CompositeNode
| Propriété / Méthode | Examples |
|---|---|
FirstChild | Premier enfant de contenu direct |
LastChild | Dernier enfant de contenu direct |
AppendChildLast(node) | Ajouter un nœud de contenu à cette cellule |
AppendChildFirst(node) | Insérer un nœud de contenu au début |
InsertChild(index, node) | Insérer à une position spécifique |
RemoveChild(node) | Supprimer un nœud de contenu |
GetChildNodes(Type) | Recherche en profondeur récursive |
for child in cell | Itérer les enfants directs |
Hérité de Node
| Examples | Examples |
|---|---|
ParentNode | Le contenant TableRow |
Document | La racine Document |
Exemples d’utilisation
Itérer toutes les lignes et cellules du tableau
from aspose.note import Document, Table, TableRow, TableCell, RichText
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
print(f"Table column widths: {[col.Width for col in table.Columns]}")
for row in table.GetChildNodes(TableRow):
row_texts = []
for cell in row.GetChildNodes(TableCell):
texts = cell.GetChildNodes(RichText)
cell_text = " ".join(rt.Text for rt in texts if rt.Text)
row_texts.append(cell_text)
print(" |", " | ".join(row_texts), "|")Extraire le texte de chaque cellule sous forme de liste plate
from aspose.note import Document, TableCell, RichText
doc = Document("MyNotes.one")
for cell in doc.GetChildNodes(TableCell):
for rt in cell.GetChildNodes(RichText):
if rt.Text.strip():
print(rt.Text)Construire une table de manière programmatique
from aspose.note import (
Document, Page, Outline, OutlineElement,
Table, TableRow, TableCell, RichText, SaveFormat
)
doc = Document()
page = doc.AppendChildLast(Page())
outline = page.AppendChildLast(Outline())
elem = outline.AppendChildLast(OutlineElement())
from aspose.note import TableColumn
table = elem.AppendChildLast(Table(
IsBordersVisible=True,
Columns=[TableColumn(Width=100.0), TableColumn(Width=200.0)],
))
headers = ["Name", "Value"]
row = table.AppendChildLast(TableRow())
for header_text in headers:
cell = row.AppendChildLast(TableCell())
rt = cell.AppendChildLast(RichText())
rt.Append(header_text)
data_row = table.AppendChildLast(TableRow())
for value in ["Item A", "42"]:
cell = data_row.AppendChildLast(TableCell())
rt = cell.AppendChildLast(RichText())
rt.Append(value)
doc.Save("table-output.pdf", SaveFormat.Pdf)Compter les lignes et les cellules
from aspose.note import Document, Table, TableRow, TableCell
doc = Document("MyNotes.one")
for table in doc.GetChildNodes(Table):
rows = table.GetChildNodes(TableRow)
cells = table.GetChildNodes(TableCell)
print(f"Rows: {len(rows)} Cells: {len(cells)}")Sécurité None
TableRow et TableCell n’ont aucune propriété propre nullable. Les listes d’enfants renvoyées par GetChildNodes sont toujours des listes (peuvent être vides).
Voir aussi
- Examples: parent de TableRow
- RichText: contenu principal dans TableCell
- Examples: contenu image dans TableCell
- CompositeNode: méthodes de gestion des enfants héritées