TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Classe: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow rappresenta una singola riga all’interno di un Table. I suoi figli diretti sono TableCell nodi.
ImageRenderOptions
TableRow non ha proprietà oltre a quelle ereditate da CompositeNode e Node.
Ereditato da CompositeNode
| Proprietà / Metodo | ImageRenderOptions |
|---|---|
FirstChild | Primo figlio diretto TableCell, o None |
LastChild | Ultimo figlio diretto TableCell, o None |
AppendChildLast(node) | Aggiungi un TableCell |
AppendChildFirst(node) | Inserisci all’inizio un TableCell |
InsertChild(index, node) | Inserisci un TableCell in una posizione specifica |
RemoveChild(node) | Rimuovi un TableCell |
GetChildNodes(Type) | Ricerca ricorsiva in profondità |
for cell in row | Itera diretto TableCell figli |
Ereditato da Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Il contenitore Table |
Document | La radice Document |
Classe: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell rappresenta una singola cella all’interno di un TableRow. Può contenere RichText, Image, e altri nodi di contenuto come figli.
ImageRenderOptions
TableCell non ha proprietà oltre a quelle ereditate da CompositeNode e Node.
Ereditato da CompositeNode
| Proprietà / Metodo | ImageRenderOptions |
|---|---|
FirstChild | Primo figlio di contenuto diretto |
LastChild | Ultimo figlio di contenuto diretto |
AppendChildLast(node) | Aggiungi un nodo di contenuto a questa cella |
AppendChildFirst(node) | Inserisci un nodo di contenuto all’inizio |
InsertChild(index, node) | Inserisci in una posizione specifica |
RemoveChild(node) | Rimuovi un nodo di contenuto |
GetChildNodes(Type) | Ricerca ricorsiva in profondità |
for child in cell | Itera i figli diretti |
Ereditato da Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Il contenitore TableRow |
Document | La radice Document |
Esempi d’uso
Itera tutte le righe e le celle della tabella
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), "|")Estrai il testo da ogni cella come una lista piatta
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)Costruisci una tabella programmaticamente
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)Conta le righe e le celle
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)}")Sicurezza None
TableRow e TableCell non hanno proprietà proprie nullable. Le liste figlio restituite da GetChildNodes sono sempre liste (possono essere vuote).
Vedi anche
- ImageRenderOptions: genitore di TableRow
- RichText: contenuto principale all’interno di TableCell
- ImageRenderOptions: contenuto immagine all’interno di TableCell
- CompositeNode: metodi di gestione dei figli ereditati