Search in sources :

Example 1 with Comment

use of org.docx4j.wml.Comments.Comment in project docx4j-template by vindell.

the class Docx4j_创建批注_S3_Test method createCommentRound.

// 创建批注(选定范围)
public void createCommentRound(ObjectFactory factory, P p, String pContent, String commentContent, RPr fontRPr, RPr commentRPr, BigInteger commentId, Comments comments) throws Exception {
    CommentRangeStart startComment = factory.createCommentRangeStart();
    startComment.setId(commentId);
    p.getContent().add(startComment);
    R run = factory.createR();
    Text txt = factory.createText();
    txt.setValue(pContent);
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    p.getContent().add(run);
    CommentRangeEnd endComment = factory.createCommentRangeEnd();
    endComment.setId(commentId);
    p.getContent().add(endComment);
    Comment commentOne = createComment(factory, commentId, "系统管理员", new Date(), commentContent, commentRPr);
    comments.getComment().add(commentOne);
    p.getContent().add(createRunCommentReference(factory, commentId));
}
Also used : CommentRangeEnd(org.docx4j.wml.CommentRangeEnd) Comment(org.docx4j.wml.Comments.Comment) R(org.docx4j.wml.R) Text(org.docx4j.wml.Text) CommentRangeStart(org.docx4j.wml.CommentRangeStart) Date(java.util.Date)

Example 2 with Comment

use of org.docx4j.wml.Comments.Comment in project docx4j-template by vindell.

the class Docx4j_创建批注_S3_Test method createComment.

public Comments.Comment createComment(ObjectFactory factory, BigInteger commentId, String author, Date date, String commentContent, RPr commentRPr) throws Exception {
    Comments.Comment comment = factory.createCommentsComment();
    comment.setId(commentId);
    if (author != null) {
        comment.setAuthor(author);
    }
    if (date != null) {
        comment.setDate(toXMLCalendar(date));
    }
    P commentP = factory.createP();
    comment.getEGBlockLevelElts().add(commentP);
    R commentR = factory.createR();
    commentP.getContent().add(commentR);
    Text commentText = factory.createText();
    commentR.getContent().add(commentText);
    commentR.setRPr(commentRPr);
    commentText.setValue(commentContent);
    return comment;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Comments(org.docx4j.wml.Comments) Comment(org.docx4j.wml.Comments.Comment) Text(org.docx4j.wml.Text)

Example 3 with Comment

use of org.docx4j.wml.Comments.Comment in project docx4j-template by vindell.

the class Docx4j_工具类_S3_Test method getComments.

public int getComments(WordprocessingMLPackage wordMLPackage) throws Exception {
    Parts parts = wordMLPackage.getParts();
    HashMap<PartName, Part> partMap = parts.getParts();
    CommentsPart commentPart = (CommentsPart) partMap.get(new CommentsPart().getPartName());
    Comments comments = commentPart.getContents();
    List<Comment> commentList = comments.getComment();
    for (Comment comment : commentList) {
        StringBuffer sb = new StringBuffer();
        sb.append(" ID: ").append(comment.getId());
        sb.append(" 作者:").append(comment.getAuthor());
        sb.append(" 时间: ").append(comment.getDate().toGregorianCalendar().getTime());
        sb.append(" 内容:").append(comment.getContent());
        // sb.append(" 文中内容:").append(docCmtMap.get(comment.getId().toString()));
        System.out.println(sb.toString());
    }
    return 0;
}
Also used : Comment(org.docx4j.wml.Comments.Comment) PartName(org.docx4j.openpackaging.parts.PartName) Parts(org.docx4j.openpackaging.parts.Parts) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) Part(org.docx4j.openpackaging.parts.Part) CommentsPart(org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart) Comments(org.docx4j.wml.Comments) CommentsPart(org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart)

Example 4 with Comment

use of org.docx4j.wml.Comments.Comment in project docx4j-template by vindell.

the class Docx4j_创建批注_S3_Test method createCommentEnd.

public void createCommentEnd(ObjectFactory factory, P p, String pContent, String commentContent, RPr fontRPr, RPr commentRPr, BigInteger commentId, Comments comments) throws Exception {
    Text txt = factory.createText();
    txt.setValue(pContent);
    R run = factory.createR();
    run.getContent().add(txt);
    run.setRPr(fontRPr);
    p.getContent().add(run);
    Comment commentOne = createComment(factory, commentId, "系统管理员", new Date(), commentContent, commentRPr);
    comments.getComment().add(commentOne);
    p.getContent().add(createRunCommentReference(factory, commentId));
}
Also used : Comment(org.docx4j.wml.Comments.Comment) R(org.docx4j.wml.R) Text(org.docx4j.wml.Text) Date(java.util.Date)

Example 5 with Comment

use of org.docx4j.wml.Comments.Comment in project docx4j-template by vindell.

the class Docx4j_删除所有批注_S3_Test method removeAllComment.

// 这里2个路径可以一致
public void removeAllComment(String filePath, String savePath) throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(filePath));
    // 清空comments.xml内容
    Parts parts = wordMLPackage.getParts();
    HashMap<PartName, Part> partMap = parts.getParts();
    CommentsPart commentPart = (CommentsPart) partMap.get(new PartName("/word/comments.xml"));
    Comments comments = commentPart.getContents();
    List<Comment> commentList = comments.getComment();
    for (int i = 0, len = commentList.size(); i < len; i++) {
        commentList.remove(0);
    }
    // 清空document.xml文件中批注
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
    org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) documentPart.getContents();
    Body body = wmlDocumentEl.getBody();
    CommentFinder cf = new CommentFinder();
    new TraversalUtil(body, cf);
    for (Child commentElement : cf.commentElements) {
        System.out.println(commentElement.getClass().getName());
        Object parent = commentElement.getParent();
        List<Object> theList = ((ContentAccessor) parent).getContent();
        boolean removeResult = remove(theList, commentElement);
        System.out.println(removeResult);
    }
    wordMLPackage.save(new FileOutputStream(savePath));
}
Also used : WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage) PartName(org.docx4j.openpackaging.parts.PartName) Parts(org.docx4j.openpackaging.parts.Parts) ContentAccessor(org.docx4j.wml.ContentAccessor) Body(org.docx4j.wml.Body) Child(org.jvnet.jaxb2_commons.ppp.Child) Comment(org.docx4j.wml.Comments.Comment) Comments(org.docx4j.wml.Comments) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) CommentsPart(org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart) TraversalUtil(org.docx4j.TraversalUtil) Part(org.docx4j.openpackaging.parts.Part) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) CommentsPart(org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart) FileOutputStream(java.io.FileOutputStream)

Aggregations

Comment (org.docx4j.wml.Comments.Comment)5 Comments (org.docx4j.wml.Comments)3 R (org.docx4j.wml.R)3 Text (org.docx4j.wml.Text)3 Date (java.util.Date)2 Part (org.docx4j.openpackaging.parts.Part)2 PartName (org.docx4j.openpackaging.parts.PartName)2 Parts (org.docx4j.openpackaging.parts.Parts)2 CommentsPart (org.docx4j.openpackaging.parts.WordprocessingML.CommentsPart)2 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)2 FileOutputStream (java.io.FileOutputStream)1 TraversalUtil (org.docx4j.TraversalUtil)1 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1 Body (org.docx4j.wml.Body)1 CommentRangeEnd (org.docx4j.wml.CommentRangeEnd)1 CommentRangeStart (org.docx4j.wml.CommentRangeStart)1 ContentAccessor (org.docx4j.wml.ContentAccessor)1 P (org.docx4j.wml.P)1 Child (org.jvnet.jaxb2_commons.ppp.Child)1