วิธีเพิ่มความคิดเห็นใน PowerPoint ด้วย Python
Aspose.Slides FOSS for Python รองรับกลไกการอธิบายสองแบบ:
- Threaded comments: แนบกับสไลด์ในตำแหน่งเฉพาะและมองเห็นได้ในแผงรีวิวของ PowerPoint
- Speaker notes: ข้อความต่อสไลด์ที่มองเห็นได้ในมุมมองผู้นำเสนอและแผงบันทึก
ข้อกำหนดเบื้องต้น
pip install aspose-slides-fossเพิ่มความคิดเห็น
ความคิดเห็นเป็นของอ็อบเจ็กต์ author. สร้าง author ก่อน, แล้วจึงเพิ่มความคิดเห็นผ่าน author.comments:
from aspose.slides_foss.drawing import PointF
from datetime import datetime
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
# Create a comment author with name and initials
author = prs.comment_authors.add_author("Jane Smith", "JS")
slide = prs.slides[0]
# Add a comment at (2.0, 2.0) inches from the slide top-left corner
author.comments.add_comment(
"Please review the figures on this slide",
slide,
PointF(2.0, 2.0),
datetime.now(),
)
prs.save("commented.pptx", SaveFormat.PPTX)พิกัด PointF อยู่ใน นิ้ว จากมุมซ้ายบนของสไลด์ การเรียกใช้ add_comment() หลายครั้งจะสร้างสายความคิดเห็นแบบต่อเนื่องภายใต้ผู้เขียนเดียวกัน.
ผู้เขียนหลายคนและความคิดเห็น
from aspose.slides_foss.drawing import PointF
from datetime import datetime
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
author1 = prs.comment_authors.add_author("Alice Brown", "AB")
author2 = prs.comment_authors.add_author("Bob Davis", "BD")
slide = prs.slides[0]
author1.comments.add_comment(
"Initial draft: needs revision",
slide, PointF(1.0, 1.0), datetime.now()
)
author2.comments.add_comment(
"Approved after changes",
slide, PointF(3.0, 1.0), datetime.now()
)
prs.save("multi-author.pptx", SaveFormat.PPTX)อ่านความคิดเห็นจากไฟล์ที่มีอยู่
import aspose.slides_foss as slides
with slides.Presentation("commented.pptx") as prs:
for author in prs.comment_authors:
print(f"Author: {author.name} ({author.initials})")
for comment in author.comments:
print(f" Slide {comment.slide.slide_number}: {comment.text}")เพิ่มบันทึกผู้พูดในสไลด์
บันทึกของผู้พูดถูกเพิ่มผ่าน slide.notes_slide_manager:
from aspose.slides_foss import ShapeType
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
slide.shapes.add_auto_shape(
ShapeType.RECTANGLE, 50, 50, 600, 300
).add_text_frame("Main slide content")
# Create the notes slide and write text
notes = slide.notes_slide_manager.add_notes_slide()
notes.notes_text_frame.text = (
"Mention the Q3 revenue increase. Emphasize the 24% YoY growth."
)
prs.save("with-notes.pptx", SaveFormat.PPTX)เพิ่มบันทึกลงในหลายสไลด์
from aspose.slides_foss import ShapeType
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
note_texts = [
"Opening: introduce the agenda and set expectations.",
"Key metrics: emphasize Q4 results and growth trajectory.",
"Closing: summarize and call to action.",
]
with slides.Presentation() as prs:
layout = prs.slides[0].layout_slide
prs.slides.add_empty_slide(layout)
prs.slides.add_empty_slide(layout)
for i, slide in enumerate(prs.slides):
slide.shapes.add_auto_shape(
ShapeType.RECTANGLE, 50, 50, 600, 300
).add_text_frame(f"Slide {i + 1}")
n = slide.notes_slide_manager.add_notes_slide()
n.notes_text_frame.text = note_texts[i]
prs.save("all-notes.pptx", SaveFormat.PPTX)ตรวจสอบว่ามีโน้ตอยู่แล้วหรือไม่
notes_slide_manager.notes_slide จะคืนค่า None หากไม่มีสไลด์บันทึกที่ถูกสร้าง:
import aspose.slides_foss as slides
with slides.Presentation("existing.pptx") as prs:
for i, slide in enumerate(prs.slides):
existing = slide.notes_slide_manager.notes_slide
if existing:
print(f"Slide {i + 1}: {existing.notes_text_frame.text[:60]}")
else:
print(f"Slide {i + 1}: no notes")