use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.
the class WordprocessingMLVelocityTemplate_Test method test.
@Test
public void test() throws Exception {
variables.put("title", "变量替换测试");
variables.put("content", "测试效果不错");
WordprocessingMLPackage wordMLPackage = velocityTemplate.process("/tpl/rythm.tpl", variables);
File outputDocx = new java.io.File("src/test/resources/output/velocityTemplate_output.docx");
wordMLPackage.save(outputDocx);
}
use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.
the class WordprocessingMLWebitTemplate_Test method test.
@Test
public void test() throws Exception {
variables.put("title", "变量替换测试");
variables.put("content", "测试效果不错");
WordprocessingMLPackage wordMLPackage = webitTemplate.process("/tpl/webit.tpl", variables);
File outputDocx = new java.io.File("src/test/resources/output/webitTemplate_output.docx");
wordMLPackage.save(outputDocx);
}
use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.
the class Docx4j_工具类_S3_Test method loadWordprocessingMLPackageWithPwd.
/**
* @Description:加载带密码WordprocessingMLPackage
*/
public WordprocessingMLPackage loadWordprocessingMLPackageWithPwd(String filePath, String password) throws Exception {
OpcPackage opcPackage = WordprocessingMLPackage.load(new java.io.File(filePath), password);
WordprocessingMLPackage wordMLPackage = (WordprocessingMLPackage) opcPackage;
return wordMLPackage;
}
use of org.docx4j.openpackaging.packages.WordprocessingMLPackage 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));
}
}
}
use of org.docx4j.openpackaging.packages.WordprocessingMLPackage in project docx4j-template by vindell.
the class HtmlConverter method xhtml2word.
/**
* 将 {@link org.jsoup.nodes.Document} 对象转为 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage}
* xhtml to word
*
* @param doc
* @return
* @throws Exception
*/
protected WordprocessingMLPackage xhtml2word(Document doc) throws Exception {
// A4纸,//横版:true
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage(PageSizePaper.valueOf("A4"), true);
// 配置中文字体
configSimSunFont(wordMLPackage);
XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
// 导入 xhtml
wordMLPackage.getMainDocumentPart().getContent().addAll(xhtmlImporter.convert(doc.html(), doc.baseUri()));
return wordMLPackage;
}
Aggregations