Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Create comment
The following example shows you how to add a comment.
import java.util.Date; import com.independentsoft.office.word.Comment; import com.independentsoft.office.word.CommentRangeEnd; import com.independentsoft.office.word.CommentRangeStart; import com.independentsoft.office.word.CommentReference; import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.WordDocument; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); Run commentRun = new Run(); commentRun.addText("Comment text."); Paragraph commentParagraph = new Paragraph(); commentParagraph.add(commentRun); Comment comment1 = new Comment(1); comment1.setAuthor("Joe Smith"); comment1.setDate(new Date()); comment1.setInitials("JS"); comment1.add(commentParagraph); CommentRangeStart commentStart = new CommentRangeStart(1); CommentRangeEnd commentEnd = new CommentRangeEnd(1); CommentReference commentReference = new CommentReference(1); Run commentReferenceRun = new Run(); commentReferenceRun.add(commentReference); Run run1 = new Run(); run1.addText("Hello "); Run run2 = new Run(); run2.addText("Word"); Run run3 = new Run(); run3.addText("."); Paragraph paragraph1 = new Paragraph(); paragraph1.add(run1); paragraph1.add(commentStart); paragraph1.add(run2); paragraph1.add(commentEnd); paragraph1.add(commentReferenceRun); paragraph1.add(run3); doc.getBody().add(paragraph1); doc.getComments().add(comment1); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*