Comment and Note (2)
Python: Add, Remove or Replace Comments in PowerPoint
2023-12-04 01:16:59 Written by support iceblueComments in Microsoft PowerPoint allow users to add additional information to specific slides or elements of a slide to improve collaboration and communication when sharing presentations. These comments can be related content, suggestions for changes, and so on. This feature is very useful when several people are working on a presentation together. In this article, you will learn how to use Spire.Presentation for Python to add, remove or replace comments on slides in Python programs.
- Add Comments to a Presentation Slide in Python
- Remove Comments from a Presentation Slide in Python
- Replace Comments on a Presentation Slide in Python
Install Spire.Presentation for Python
This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip commands.
pip install Spire.Presentation
If you are unsure how to install, please refer to this tutorial: How to Install Spire.Presentation for Python on Windows
Add Comments to a Presentation Slide in Python
Spire.Presentation for Python provides the Presentation.CommentAuthors.AddAuthor() and Presentation.Slides[].AddComment(author:ICommentAuthor,text:str,position:PointF,dateTime:DateTime) methods to support adding comments to a slide. The detailed steps are as follows.
- Create a new PowerPoint presentation.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Add the author of the comment by using Presentation.CommentAuthors.AddAuthor() method.
- Then add a comment to the first slide using Presentation.Slides[].AddComment(author:ICommentAuthor,text:str,position:PointF,dateTime:DateTime) method.
- Add another comment using the same method.
- Save the result file using Presentation.SaveToFile() method.
- Python
from spire.presentation.common import * from spire.presentation import * inputFile = "C:/Users/Administrator/Desktop/Sample.pptx" outputFile = "C:/Users/Administrator/Desktop/AddComment.pptx" # Create a Presentation instance presentation = Presentation() # Load a presentation from disk presentation.LoadFromFile(inputFile) # Add the author of the comment author = presentation.CommentAuthors.AddAuthor("E-iceblue", "comment:") # Add a comment to the first slide point = PointF(45.0,12.0) presentation.Slides[0].AddComment(author, "Overview", point, DateTime.get_Now()) # Add another comment to this slide author = presentation.CommentAuthors.AddAuthor("E-iceblue", "comment:") point = PointF(35.0,23.0) presentation.Slides[0].AddComment(author, "Features", point, DateTime.get_Now()) # Save the result file presentation.SaveToFile(outputFile, FileFormat.Pptx2010) presentation.Dispose()
Remove Comments from a Presentation Slide in Python
You can also remove the specific comment from the slides by using Presentation.Slides[].DeleteComment(Comment) method. The detailed steps are as follows.
- Create a Presentation instance.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Remove the first comment from the specified slide using Presentation.Slides[].DeleteComment(Comment) method.
- Save the result file using Presentation.SaveToFile() method.
- Python
from spire.presentation.common import * from spire.presentation import * inputFile = "C:/Users/Administrator/Desktop/AddComment.pptx" outputFile = "C:/Users/Administrator/Desktop/DeleteComment.pptx" # Create a Presentation instance presentation = Presentation() # Load a presentation from disk presentation.LoadFromFile(inputFile) # Delete the first comment from the first slide presentation.Slides[0].DeleteComment(presentation.Slides[0].Comments[0]) # Save the result file presentation.SaveToFile(outputFile, FileFormat.Pptx2010) presentation.Dispose()
Replace Comments on a Presentation Slide in Python
If you want to replace the comment content with new text, please use the Presentation.Slides[].Comments[].Text property. The detailed steps are as follows.
- Create a Presentation instance.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Replace the content of the second comment with new text by Presentation.Slides[].Comments[].Text property.
- Save the result file using Presentation.SaveToFile() method.
- Python
from spire.presentation.common import * from spire.presentation import * inputFile = "C:/Users/Administrator/Desktop/AddComment.pptx" outputFile = "C:/Users/Administrator/Desktop/ReplaceComment.pptx" # Create a Presentation instance presentation = Presentation() # Load a presentation from disk presentation.LoadFromFile(inputFile) # Replace the content of the second comment with new text presentation.Slides[0].Comments[1].Text = "Replace comment" # Save the result file presentation.SaveToFile(outputFile, FileFormat.Pptx2010) presentation.Dispose()
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Python: Add, Read or Delete Speaker Notes in PowerPoint
2023-11-07 07:51:37 Written by support iceblueSpeaker notes in PowerPoint play a crucial role in enhancing the presenter's delivery and ensuring a seamless presentation experience. They can be added to individual slides to provide valuable guidance, reminders, and supplementary information for the presenter. Unlike the content displayed on the slides, speaker notes are typically not visible to the audience during the actual presentation. In this article, we'll explain how to add, read or delete speaker notes in a PowerPoint presentation in Python using Spire.Presentation for Python.
- Add Speaker Notes to PowerPoint in Python
- Read Speaker Notes in PowerPoint in Python
- Delete Speaker Notes from PowerPoint in Python
Install Spire.Presentation for Python
This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.
pip install Spire.Presentation
If you are unsure how to install, please refer to this tutorial: How to Install Spire.Presentation for Python on Windows
Add Speaker Notes to PowerPoint in Python
Spire.Presentation for Python provides the ISlide.AddNotesSlides() method to add notes to a PowerPoint slide. The detailed steps are as follows.
- Create a Presentation object.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Get the slide that you want to add notes to using Presentation.Slides[index] property.
- Add a notes slide to the slide using ISlide.AddNotesSlides() method.
- Create TextParagraph objects and set text for the paragraphs using TextParagraph.Text property, then add the paragraphs to the notes slide using NotesSlide.NotesTextFrame.Paragraphs.Append() method.
- Save the resulting presentation using Presentation.SaveToFile() method.
- Python
from spire.presentation.common import * from spire.presentation import * # Create a Presentation object ppt = Presentation() # Load a PowerPoint presentation ppt.LoadFromFile("Sample.pptx") # Get the first slide slide = ppt.Slides[0] # Add a notes slide to the slide notesSlide = slide.AddNotesSlide() # Add 4 paragraphs to the notes slide paragraph = TextParagraph() paragraph.Text = "Tips for making effective presentations:" notesSlide.NotesTextFrame.Paragraphs.Append(paragraph) paragraph = TextParagraph() paragraph.Text = "Use the slide master feature to create a consistent and simple design template." notesSlide.NotesTextFrame.Paragraphs.Append(paragraph) paragraph = TextParagraph() paragraph.Text = "Simplify and limit the number of words on each screen." notesSlide.NotesTextFrame.Paragraphs.Append(paragraph) paragraph = TextParagraph() paragraph.Text = "Use contrasting colors for text and background." notesSlide.NotesTextFrame.Paragraphs.Append(paragraph) # Set bullet type and style for specific paragraphs for i in range(1, notesSlide.NotesTextFrame.Paragraphs.Count): notesSlide.NotesTextFrame.Paragraphs[i].BulletType = TextBulletType.Numbered notesSlide.NotesTextFrame.Paragraphs[i].BulletStyle = NumberedBulletStyle.BulletArabicPeriod # Save the resulting presentation ppt.SaveToFile("AddSpeakerNotes.pptx", FileFormat.Pptx2016) ppt.Dispose()
Read Speaker Notes in PowerPoint in Python
To read the text content of the notes, you can use the NotesSlide.NotesTextFrame.Text property. The detailed steps are as follows.
- Create a Presentation object.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Get the slide that you want to read notes from using Presentation.Slides[index] property.
- Get the notes slide of the slide using ISlide.NotesSlide property.
- Get the text content of the notes slide using NotesSlide.NotesTextFrame.Text property.
- Write the text content into a text file.
- Python
from spire.presentation.common import * from spire.presentation import * # Create a Presentation object ppt = Presentation() # Load a PowerPoint presentation ppt.LoadFromFile("AddSpeakerNotes.pptx") # Get the first slide slide = ppt.Slides[0] # Get the notes slide of the slide notesSlide = slide.NotesSlide # Get the text content of the notes slide notes = notesSlide.NotesTextFrame.Text # Write the text content to a text file with open("Notes.txt", 'w') as file: file.write(notes) ppt.Dispose()
Delete Speaker Notes from PowerPoint in Python
You can delete a specific paragraph of note or delete all the notes from a slide using the NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(index) or NotesSlide.NotesTextFrame.Paragraphs.Clear() method. The detailed steps are as follows.
- Create a Presentation object.
- Load a PowerPoint presentation using Presentation.LoadFromFile() method.
- Get the slide that you want to delete notes from using Presentation.Slides[index] property.
- Get the notes slide of the slide using ISlide.NotesSlide property.
- Delete a specific paragraph of note or delete all the notes from the notes slide using the NotesSlide.NotesTextFrame.Paragraphs.RemoveAt(index) or NotesSlide.NotesTextFrame.Paragraphs.Clear() method.
- Save the resulting presentation using Presentation.SaveToFile() method.
- Python
from spire.presentation.common import * from spire.presentation import * # Create a Presentation object presentation = Presentation() # Load a PowerPoint presentation presentation.LoadFromFile("AddSpeakerNotes.pptx") # Get the first slide slide = presentation.Slides[0] # Get the notes slide of the slide notesSlide = slide.NotesSlide # Remove a specific paragraph of note from the notes slide # notesSlide.NotesTextFrame.Paragraphs.RemoveAt(1) # Remove all the notes from the notes slide notesSlide.NotesTextFrame.Paragraphs.Clear() # Save the resulting presentation presentation.SaveToFile("DeleteSpeakerNotes.pptx", FileFormat.Pptx2013) presentation.Dispose()
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.