TableRow / TableCell — Aspose.Note FOSS for Python API Reference
Klasė: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow reprezintuoja vieną eilutę Table. Jo tiesioginiai vaikai yra TableCell mazgai.
ImageRenderOptions
TableRow neturi savybių, išskyrus tas, kurios paveldimos iš CompositeNode ir Node.
Paveldėta iš CompositeNode
| Savybė / Metodas | ImageRenderOptions |
|---|---|
FirstChild | Pirmas tiesioginis vaikas TableCell, arba None |
LastChild | Paskutinis tiesioginis vaikas TableCell, arba None |
AppendChildLast(node) | Pridėti TableCell |
AppendChildFirst(node) | Pridėti į pradžią TableCell |
InsertChild(index, node) | Įterpti TableCell konkrečioje pozicijoje |
RemoveChild(node) | Pašalinti TableCell |
GetChildNodes(Type) | Rekursinė gylio pirmumo paieška |
for cell in row | Iteruoti tiesiogiai TableCell vaikai |
Paveldėta iš Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Turintis Table |
Document | Šaknis Document |
Klasė: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell žymi vieną langelį, esantį TableRow.Gali turėti RichText, Image, ir kitus turinio mazgus kaip vaikus.
ImageRenderOptions
TableCell neturi jokių savybių, išskyrus tas, kurios paveldimos iš CompositeNode ir Node.
Paveldėta iš CompositeNode
| Savybė / Metodas | ImageRenderOptions |
|---|---|
FirstChild | Pirmas tiesioginis turinio vaikas |
LastChild | Paskutinis tiesioginis turinio vaikas |
AppendChildLast(node) | Pridėti turinio mazgą prie šio langelio |
AppendChildFirst(node) | Įdėti turinio mazgą į pradžią |
InsertChild(index, node) | Įterpti į konkrečią poziciją |
RemoveChild(node) | Pašalinti turinio mazgą |
GetChildNodes(Type) | Rekursinė gylio pirmumo paieška |
for child in cell | Iteruoti tiesioginius vaikus |
Paveldėta iš Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | Konteineris TableRow |
Document | Šaknis Document |
Naudojimo pavyzdžiai
Iteruokite visas lentelės eilutes ir langelius
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), "|")Išskirkite tekstą iš kiekvieno langelio kaip plokščią sąrašą
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)Sukurkite lentelę programiškai
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)Suskaičiuokite eilutes ir langelius
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)}")None-saugumas
TableRow ir TableCell neturi nullable savų savybių. Vaikų sąrašai, grąžinami pagal GetChildNodes visada yra sąrašai (gali būti tušti).
Žr. taip pat
- ImageRenderOptions: TableRow tėvas
- RichText: pirminis turinys TableCell viduje
- ImageRenderOptions: vaizdo turinys TableCell viduje
- CompositeNode: paveldėti vaikų valdymo metodai