An overview of the

Comments are comments and comments on specific words in a document. They are commonly used in office documents such as Word, Excel, PowerPoint, and PDF. This article will use Java programs to demonstrate how to add comments, modify comments, obtain comments, and delete comments in a PowerPoint document. It will be divided into three Java examples. In this test environment, IDEA compilation environment was used, JDK version was 1.8.0, and spire.present.jar (free version) file was introduced into the program.

Detailed code examples

1. Add comments

import com.spire.presentation.*; import java.awt.geom.Point2D; import java.time.Instant; import java.util.Date; Public class AddComment {public static void main(String[] args) throws Exception{// Load test document Presentation PPT = new Presentation(); ppt.loadFromFile("test.pptx"); ISlide slide = ppt.getslides ().get(1); ICommentAuthor author = ppt.getCommentauthors ().addauthor ("Tom"," thor "); Slide. addComment(author," Please upload backup file! ") , a new Point2D. Float (25, 8), the Date, the from (Instant. Now ())); Slide. addComment(author," Please add an attachment!" ,new point2d.float (40, (Float) 28.5), date.from (instant.now ())); SaveToFile ("addcomment.pptx", fileformat.pptx_2010); ppt.dispose(); }}Copy the code

2. Modify and delete comments

import com.spire.presentation.*; Public class ModifyAndRemoveComment {public static void main(String[] args) throws Exception {// Load the test document Presentation ppt = new Presentation(); ppt.loadFromFile("sample.pptx"); ISlide slide = ppt.getSlides().get(1); Slide.getcomments ()[0].settext (" New comments "); Slide.deletecomment (slide.getComments()[1]); / / save the document PPT. SaveToFile (" replaceAnddeletecomment. PPTX ", FileFormat. PPTX_2010); ppt.dispose(); }}Copy the code

3. Get comments

import com.spire.presentation.*; import java.util.Date; Public class GetComment {public static void main(String[] args) throws Exception{// Load PPT Presentation PPT = new Presentation(); ppt.loadFromFile("addcomment.pptx"); ISlide slide = pp.getslides ().get(1); Comment = slide.getComments()[0]; String author = comment.getAuthorName(); String commenttext = comment.getText(); Date time = comment.getDateTime(); System.out.println(" Comment author: "+ author + "\n" +" Add comment time: "+ time + "\n" +" comment content: "+ commenttext + "\n"); }}Copy the code