use of org.jvnet.jaxb2_commons.ppp.Child in project docx4j-template by vindell.
the class SdtFinder method printSdtContent.
public void printSdtContent(String filePath) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(filePath));
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
Document wmlDocumentEl = (Document) mdp.getContents();
Body body = wmlDocumentEl.getBody();
SdtFinder sdtFinder = new SdtFinder();
new TraversalUtil(body, sdtFinder);
for (Child sdtChild : sdtFinder.sdtList) {
if (sdtChild instanceof SdtRun) {
SdtRun sdtRun = (SdtRun) sdtChild;
SdtPr sdtPr = sdtRun.getSdtPr();
printSdtPrContent(sdtPr);
// System.out.println(XmlUtils.marshaltoString(sdtPr, true,
// true));
SdtContent sdtContent = sdtRun.getSdtContent();
System.out.println("-----------p content=" + getContentAccessorContent(sdtContent));
} else if (sdtChild instanceof CTSdtCell) {
CTSdtCell sdtCell = (CTSdtCell) sdtChild;
SdtPr sdtPr = sdtCell.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtCell.getSdtContent();
System.out.println("-----------table content=" + getContentAccessorContent(sdtContent));
} else if (sdtChild instanceof SdtBlock) {
SdtBlock sdtBlock = (SdtBlock) sdtChild;
SdtPr sdtPr = sdtBlock.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtBlock.getSdtContent();
System.out.println("-----------sdtblock content=" + getContentAccessorContent(sdtContent));
}
}
}
use of org.jvnet.jaxb2_commons.ppp.Child 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));
}
use of org.jvnet.jaxb2_commons.ppp.Child in project docx4j-template by vindell.
the class SdtFinder_2 method printSdtContent.
public void printSdtContent(String filePath) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(filePath));
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
Document wmlDocumentEl = (Document) mdp.getContents();
Body body = wmlDocumentEl.getBody();
SdtFinder_2 sdtFinder = new SdtFinder_2();
new TraversalUtil(body, sdtFinder);
for (Child sdtChild : sdtFinder.sdtList) {
if (sdtChild instanceof SdtRun) {
SdtRun sdtRun = (SdtRun) sdtChild;
SdtPr sdtPr = sdtRun.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtRun.getSdtContent();
System.out.println("-----------p content=" + getSdtContentContent(sdtContent));
} else if (sdtChild instanceof CTSdtCell) {
CTSdtCell sdtCell = (CTSdtCell) sdtChild;
SdtPr sdtPr = sdtCell.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtCell.getSdtContent();
System.out.println("-----------table content=" + getSdtContentContent(sdtContent));
} else if (sdtChild instanceof SdtBlock) {
SdtBlock sdtBlock = (SdtBlock) sdtChild;
SdtPr sdtPr = sdtBlock.getSdtPr();
printSdtPrContent(sdtPr);
SdtContent sdtContent = sdtBlock.getSdtContent();
System.out.println("-----------sdtblock content=" + getSdtContentContent(sdtContent));
}
}
}
Aggregations