TableRow / TableCell — Aspose.Note FOSS for Python API Reference
کلاس: TableRow
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableRow ImageRenderOptions: CompositeNode
TableRow نمایانگر یک ردیف تک در یک Table. فرزندان مستقیم آن عبارتند از TableCell گرهها.
ImageRenderOptions
TableRow هیچ ویژگیای فراتر از آنچه از CompositeNode و Node.
ارثبری شده از CompositeNode
| ویژگی / متد | ImageRenderOptions |
|---|---|
FirstChild | اولین فرزند مستقیم TableCell,، یا None |
LastChild | آخرین فرزند مستقیم TableCell,، یا None |
AppendChildLast(node) | یک مورد را اضافه کنید TableCell |
AppendChildFirst(node) | یک مورد را در ابتدا اضافه کنید TableCell |
InsertChild(index, node) | یک مورد را وارد کنید TableCell در موقعیت خاصی |
RemoveChild(node) | یک مورد را حذف کنید TableCell |
GetChildNodes(Type) | جستجوی عمقاول بازگشتی |
for cell in row | بهصورت مستقیم تکرار کنید TableCell فرزندان |
ارثبری شده از Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | محتوی Table |
Document | ریشه Document |
کلاس: TableCell
ImageRenderOptions: aspose.note ImageRenderOptions: from aspose.note import TableCell ImageRenderOptions: CompositeNode
TableCell نمایش یک سلول منفرد در یک TableRow.میتواند شامل RichText, Image,، و سایر گرههای محتوا به عنوان فرزند.
ImageRenderOptions
TableCell هیچ ویژگیای جز آنچه از CompositeNode و Node.
ارثبری شده از CompositeNode
| ویژگی / متد | ImageRenderOptions |
|---|---|
FirstChild | اولین فرزند مستقیم محتوا |
LastChild | آخرین فرزند مستقیم محتوا |
AppendChildLast(node) | یک گره محتوا را به این سلول اضافه کنید |
AppendChildFirst(node) | یک گره محتوا را در ابتدای آن اضافه کنید |
InsertChild(index, node) | در موقعیت خاصی درج کنید |
RemoveChild(node) | گره محتوا را حذف کنید |
GetChildNodes(Type) | جستجوی عمقاول بازگشتی |
for child in cell | بر فرزندان مستقیم تکرار کنید |
ارثبری شده از Node
| ImageRenderOptions | ImageRenderOptions |
|---|---|
ParentNode | حاوی TableRow |
Document | ریشه Document |
مثالهای استفاده
تکرار تمام ردیفها و سلولهای جدول
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), "|")استخراج متن از هر سلول به صورت یک لیست صاف
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)ساخت جدول بهصورت برنامهنویسی
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)شمارش ردیفها و سلولها
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
TableRow و TableCell هیچ ویژگی مالک قابلnull ندارند. فهرستهای فرزندی که توسط GetChildNodes همواره لیست هستند (ممکن است خالی باشند).
همچنین ببینید
- ImageRenderOptions: والد TableRow
- RichText: محتوای اصلی داخل TableCell
- ImageRenderOptions: محتوای تصویر داخل TableCell
- CompositeNode: متدهای مدیریت فرزند به ارثبرده شده