PageBreak

PageBreak — Aspose.Cells FOSS for Python API Reference

aspose-cells-foss อนุญาตให้แทรกการแบ่งหน้าแบบแมนนวลเพื่อควบคุมว่าชีตทำงานจะแบ่งเป็นหน้าอย่างไรเมื่อพิมพ์. การแบ่งหน้าตามแนวนอนจะแบ่งชีตระหว่างแถว; การแบ่งหน้าตามแนวตั้งจะแบ่งระหว่างคอลัมน์. ทั้งสองคอลเลกชันใช้ 0-based indices.

Properties: aspose.cells_foss

from aspose.cells_foss import Workbook

wb = Workbook("report.xlsx")
ws = wb.worksheets[0]

hpb = ws.horizontal_page_breaks
vpb = ws.vertical_page_breaks

HorizontalPageBreakCollection

เข้าถึงได้เป็น ws.horizontal_page_breaks. การแบ่งหน้าตามแนวนอนที่แทรกก่อนแถว n ทำให้ชีตเริ่มหน้าต่อไปที่แถวนั้นเมื่อพิมพ์.

การอ้างอิงแถวทั้งหมดคือ 0-based (แถว 0 = แถว 1 ใน Excel).

Properties

add

hpb.add(row_or_cell: int | str) -> int

เพิ่มการแบ่งหน้าก่อนแถวที่ระบุ. คืนค่าดัชนีเริ่มจาก 0 ของการแบ่งหน้าใหม่ในคอลเลกชัน.

PropertiesPropertiesProperties
row_or_cellint0-based row index at which to insert the break.
row_or_cellstrการอ้างอิงเซลล์แบบ A1; แถวของเซลล์นี้จะถูกใช้ (เช่น,., "A11" → แบ่งหน้าก่อนแถว 10 ในระบบนับจาก 0).

remove

hpb.remove(row_or_cell: int | str)

ลบการแบ่งหน้าที่เชื่อมโยงกับดัชนีแถวหรืออ้างอิงเซลล์ที่ระบุ.

remove_at

hpb.remove_at(index: int)

ลบการแบ่งหน้าที่ตำแหน่งเริ่มจาก 0 ที่กำหนดในคอลเลกชัน.

clear

hpb.clear()

ลบการแบ่งหน้าตามแนวนอนทั้งหมดจากเวิร์กชีต.

to_list

hpb.to_list() -> list

คืนค่าเป็นรายการ Python ธรรมดาของดัชนีแถวการแบ่งหน้าปัจจุบัน (จำนวนเต็มเริ่มจาก 0) ที่เรียงลำดับจากน้อยไปมาก.

คุณสมบัติและการวนซ้ำ

PropertiesProperties
countจำนวนการแบ่งหน้าตามแนวนอน (อ่านอย่างเดียว).
__len__()Properties count.
__iter__()วนซ้ำผ่านดัชนีแถวที่แบ่งหน้า.
__getitem__(index)คืนค่าดัชนีแถวที่แบ่งหน้าที่ตำแหน่ง index ในคอลเลกชัน.

VerticalPageBreakCollection

เข้าถึงได้เป็น ws.vertical_page_breaks. การแบ่งหน้าตามแนวตั้งที่แทรกก่อนคอลัมน์ n ทำให้ชีตเริ่มหน้าต่อไปที่คอลัมน์นั้นเมื่อพิมพ์.

การอ้างอิงคอลัมน์ทั้งหมดคือ 0-based (คอลัมน์ 0 = คอลัมน์ A).

Properties

add

vpb.add(column_or_cell: int | str) -> int

เพิ่มการแบ่งหน้าก่อนคอลัมน์ที่ระบุ. คืนค่าดัชนีเริ่มจาก 0 ของการแบ่งหน้าใหม่ในคอลเลกชัน.

PropertiesPropertiesProperties
column_or_cellint0-based column index at which to insert the break.
column_or_cellstrการอ้างอิงเซลล์แบบ A1; คอลัมน์ของเซลล์นี้จะถูกใช้ (เช่น,., "E1" → แบ่งก่อนคอลัมน์ 4 ในการนับจากศูนย์).

remove

vpb.remove(column_or_cell: int | str)

ลบการแบ่งหน้าที่เชื่อมโยงกับดัชนีคอลัมน์หรืออ้างอิงเซลล์ที่ระบุ.

clear

vpb.clear()

ลบการแบ่งหน้าตามแนวตั้งทั้งหมดจากเวิร์กชีต.

to_list

vpb.to_list() -> list

คืนค่าเป็นรายการ Python ธรรมดาของดัชนีคอลัมน์การแบ่งปัจจุบัน (จำนวนเต็มที่เริ่มจาก 0) ที่เรียงลำดับจากน้อยไปมาก.

คุณสมบัติและการวนซ้ำ

PropertiesProperties
countจำนวนการแบ่งหน้าตั้งแนวตั้ง (อ่านอย่างเดียว).
__len__()Properties count.
__iter__()วนซ้ำผ่านดัชนีคอลัมน์การตัด.
__getitem__(index)คืนค่าดัชนีคอลัมน์การตัดที่ตำแหน่ง index ในคอลเลกชัน.

Properties

ตัวอย่างต่อไปนี้แทรกการแบ่งหน้าตามแนวนอนทุก 30 แถวเพื่อให้ได้หน้าพิมพ์ที่แบ่งเท่า ๆ กันในรายงานขนาดใหญ่.

from aspose.cells_foss import Workbook

wb = Workbook()
ws = wb.worksheets[0]
ws.name = "AnnualReport"

# Write 120 rows of placeholder data
for row in range(120):
    ws.cells[row][0].put_value(f"Row {row + 1}")
    ws.cells[row][1].put_value(row * 100)

# Insert a page break before rows 30, 60, and 90 (0-based)
ws.horizontal_page_breaks.add(30)
ws.horizontal_page_breaks.add(60)
ws.horizontal_page_breaks.add(90)

print(f"Page breaks at rows: {ws.horizontal_page_breaks.to_list()}")
# Output: Page breaks at rows: [30, 60, 90]

# Add a vertical break to split wide reports after column D (index 4)
ws.vertical_page_breaks.add(4)

wb.save("annual_report_paged.xlsx")

การลบการแบ่งเฉพาะ

from aspose.cells_foss import Workbook

wb = Workbook("annual_report_paged.xlsx")
ws = wb.worksheets[0]

# Remove the break at row 60 (0-based)
ws.horizontal_page_breaks.remove(60)

print(f"Remaining breaks: {ws.horizontal_page_breaks.to_list()}")
# Output: Remaining breaks: [30, 90]

wb.save("annual_report_paged.xlsx")

ดูเพิ่มเติม

 ภาษาไทย