คุณลักษณะและความสามารถ
คุณลักษณะและความสามารถ
Aspose.Slides FOSS for Python provides a broad set of capabilities for working with PowerPoint .pptx ไฟล์โดยโปรแกรมมิ่ง หน้านี้แสดงรายการพื้นที่ฟีเจอร์ที่รองรับทั้งหมดพร้อมตัวอย่างโค้ดที่เป็นตัวแทน.
การอ่าน/เขียนงานนำเสนอ
เปิดไฟล์ที่มีอยู่แล้ว .pptx ไฟล์หรือสร้างไฟล์ใหม่ แล้วบันทึกกลับเป็นรูปแบบ PPTX.
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
# Open an existing presentation
with slides.Presentation("input.pptx") as prs:
print(f"Slide count: {len(prs.slides)}")
prs.save("output.pptx", SaveFormat.PPTX)
# Create a new presentation (starts with one blank slide)
with slides.Presentation() as prs:
prs.save("new.pptx", SaveFormat.PPTX)หมายเหตุ: PPTX เป็นรูปแบบการบันทึกที่รองรับเดียว การส่งออกเป็น PDF, HTML, SVG หรือรูปภาพไม่สามารถทำได้.
ส่วน XML ที่ไม่รู้จักในไฟล์ต้นฉบับจะถูกเก็บไว้ตามต้นฉบับเมื่อตอนบันทึก ดังนั้นการเปิดและบันทึกใหม่ของ .pptx จะไม่มีการลบเนื้อหาที่ไลบรารียังไม่เข้าใจ.
การจัดการสไลด์
เพิ่ม, ลบ, คัดลอก, และจัดลำดับสไลด์ใหม่.
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
# Access the first slide
slide = prs.slides[0]
# Add an additional blank slide at the end
prs.slides.add_empty_slide(prs.layout_slides[0])
print(f"Total slides: {len(prs.slides)}")
prs.save("multi-slide.pptx", SaveFormat.PPTX)รูปร่าง
เพิ่ม AutoShapes, PictureFrames, ตาราง, และตัวเชื่อมต่อไปยังสไลด์.
AutoShapes
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
# Add a rectangle at (x=50, y=50) with width=300, height=100
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 100)
shape.add_text_frame("Aspose.Slides FOSS")
prs.save("shapes.pptx", SaveFormat.PPTX)ตาราง
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
# Column widths and row heights in points
col_widths = [120.0, 120.0, 120.0]
row_heights = [40.0, 40.0, 40.0]
table = slide.shapes.add_table(50, 50, col_widths, row_heights)
table.rows[0][0].text_frame.text = "Product"
table.rows[0][1].text_frame.text = "Quantity"
table.rows[0][2].text_frame.text = "Price"
prs.save("table.pptx", SaveFormat.PPTX)ตัวเชื่อมต่อ
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
box1 = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 100, 150, 60)
box2 = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 350, 100, 150, 60)
conn = slide.shapes.add_connector(ShapeType.BENT_CONNECTOR3, 0, 0, 10, 10)
conn.start_shape_connected_to = box1
conn.start_shape_connection_site_index = 3 # right side
conn.end_shape_connected_to = box2
conn.end_shape_connection_site_index = 1 # left side
prs.save("connector.pptx", SaveFormat.PPTX)การจัดรูปแบบข้อความ
จัดรูปแบบข้อความในระดับย่อหน้าและอักขระโดยใช้ PortionFormat.
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, NullableBool, FillType
from aspose.slides_foss.drawing import Color
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 500, 150)
tf = shape.add_text_frame("Bold blue heading")
fmt = tf.paragraphs[0].portions[0].portion_format
fmt.font_height = 28
fmt.font_bold = NullableBool.TRUE
fmt.fill_format.fill_type = FillType.SOLID
fmt.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 70, 127)
prs.save("text.pptx", SaveFormat.PPTX)NullableBool.TRUE ตั้งค่าคุณสมบัตินี้อย่างชัดเจน; NullableBool.NOT_DEFINED สืบทอดจากสไลด์มาสเตอร์.
ประเภทการเติม
ใช้การเติมแบบสีทึบ, ไล่สี, ลวดลาย หรือรูปภาพกับรูปร่าง.
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType
from aspose.slides_foss.drawing import Color
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
# Solid fill
shape.fill_format.fill_type = FillType.SOLID
shape.fill_format.solid_fill_color.color = Color.from_argb(255, 30, 120, 200)
prs.save("fill.pptx", SaveFormat.PPTX)เอฟเฟกต์ภาพ
ใช้เงานอก, แสงเรืองแสง, ขอบนุ่ม, เบลอ, การสะท้อน และเงาภายในกับรูปร่าง.
คุณสมบัติของเอฟเฟกต์สามารถเข้าถึงได้ผ่าน shape.effect_format. ตั้งค่า outer_shadow_effect, glow_effect, soft_edge_effect, blur_effect, reflection_effect, หรือ inner_shadow_effect เพื่อกำหนดค่าแต่ละอย่างแยกกัน.
3D Formatting
ใช้ 3D bevel, กล้อง, ระบบแสง, วัสดุ, และความลึกการดันออกผ่าน shape.three_d_format. สิ่งนี้ควบคุมความลึกเชิงภาพและโมเดลแสงสำหรับการเรนเดอร์รูปร่างในโปรแกรมดู PPTX ที่รองรับเอฟเฟกต์ 3D.
บันทึกผู้บรรยาย
แนบบันทึกย่อไปยังสไลด์ใดก็ได้โดยใช้ notes_slide_manager.
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
notes = prs.slides[0].notes_slide_manager.add_notes_slide()
notes.notes_text_frame.text = "Key talking point: emphasize the ROI benefit."
prs.save("notes.pptx", SaveFormat.PPTX)ความคิดเห็น
เพิ่มความคิดเห็นแบบเธรดพร้อมข้อมูลผู้เขียนและตำแหน่งสไลด์.
import aspose.slides_foss as slides
from aspose.slides_foss.drawing import PointF
from aspose.slides_foss.export import SaveFormat
from datetime import datetime
with slides.Presentation() as prs:
author = prs.comment_authors.add_author("Jane Smith", "JS")
slide = prs.slides[0]
author.comments.add_comment(
"Please verify this data before the presentation.",
slide,
PointF(2.0, 2.0),
datetime.now()
)
prs.save("comments.pptx", SaveFormat.PPTX)ภาพฝัง
ฝังรูปภาพจากเส้นทางไฟล์ลงในงานนำเสนอและเพิ่มลงในสไลด์เป็น PictureFrame.
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
with open("logo.png", "rb") as f:
image_data = f.read()
image = prs.images.add_image(image_data)
slide = prs.slides[0]
slide.shapes.add_picture_frame(
slides.ShapeType.RECTANGLE, 50, 50, 200, 150, image
)
prs.save("with-image.pptx", SaveFormat.PPTX)คุณสมบัติเอกสาร
อ่านและเขียนคุณสมบัติเอกสารหลัก, แอป, และคุณสมบัติที่กำหนดเอง.
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
props = prs.document_properties
# Core properties
props.title = "Q1 Results"
props.author = "Finance Team"
props.subject = "Quarterly Review"
props.keywords = "Q1, finance, results"
# Custom property
props.set_custom_property_value("ReviewedBy", "Legal Team")
prs.save("deck.pptx", SaveFormat.PPTX)ข้อจำกัดที่ทราบ
ส่วนต่อไปนี้ทำให้เกิด NotImplementedError และไม่พร้อมใช้งานในฉบับนี้:
| พื้นที่ | สถานะ |
|---|---|
| แผนภูมิ | ยังไม่ได้ดำเนินการ |
| SmartArt | ยังไม่ได้ดำเนินการ |
| การเคลื่อนไหวและการเปลี่ยนฉาก | ยังไม่ได้ดำเนินการ |
| การส่งออก PDF / HTML / SVG / รูปภาพ | ยังไม่ได้ดำเนินการ (เฉพาะ PPTX) |
| แมโคร VBA | ยังไม่ได้ดำเนินการ |
| ลายเซ็นดิจิทัล | ยังไม่ได้ดำเนินการ |
| ไฮเปอร์ลิงก์และการตั้งค่าการกระทำ | ยังไม่ได้ดำเนินการ |
| อ็อบเจกต์ OLE | ยังไม่ได้ดำเนินการ |
| ข้อความคณิตศาสตร์ | ยังไม่ได้ดำเนินการ |
ดูเพิ่มเติม
- เริ่มต้นใช้งาน: การติดตั้งและสคริปต์แรก
- อ้างอิง API: การอ้างอิงคลาสและเมธอด
- คู่มือวิธีทำ: บทความเชิงงาน