当前位置: 首页>>代码示例>>Java>>正文


Java WordprocessingMLPackage.load方法代码示例

本文整理汇总了Java中org.docx4j.openpackaging.packages.WordprocessingMLPackage.load方法的典型用法代码示例。如果您正苦于以下问题:Java WordprocessingMLPackage.load方法的具体用法?Java WordprocessingMLPackage.load怎么用?Java WordprocessingMLPackage.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.docx4j.openpackaging.packages.WordprocessingMLPackage的用法示例。


在下文中一共展示了WordprocessingMLPackage.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: docxToHtml

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 * 把docx转成html
 * @param docxFilePath
 * @param htmlPath
 * @throws Exception
 */
public static void docxToHtml(String docxFilePath, String htmlPath) throws Exception {
	OutputStream output = null;
	try {
		//
		WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(new File(docxFilePath));

		WMLPACKAGE_BUILDER.configChineseFonts(wmlPackage).configSimSunFont(wmlPackage);
		
		WMLPACKAGE_WRITER.writeToHtml(wmlPackage, htmlPath);

	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		IOUtils.closeQuietly(output);
	}

}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:24,代码来源:Docx4jUtils.java

示例2: saveDocxImg

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/** 
 * @Description: 提取word图片 
 */  
public void saveDocxImg(String filePath, String savePath) throws Exception {  
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage  
            .load(new File(filePath));  
    for (Entry<PartName, Part> entry : wordMLPackage.getParts().getParts()  
            .entrySet()) {  
        if (entry.getValue() instanceof BinaryPartAbstractImage) {  
            BinaryPartAbstractImage binImg = (BinaryPartAbstractImage) entry  
                    .getValue();  
            // 图片minetype  
            String imgContentType = binImg.getContentType();  
            PartName pt = binImg.getPartName();  
            String fileName = null;  
            if (pt.getName().indexOf("word/media/") != -1) {  
                fileName = pt.getName().substring(  
                        pt.getName().indexOf("word/media/")  
                                + "word/media/".length());  
            }  
            System.out.println(String.format("mimetype=%s,filePath=%s",  
                    imgContentType, pt.getName()));  
            FileOutputStream fos = new FileOutputStream(savePath + fileName);  
            ((BinaryPart) entry.getValue()).writeDataToOutputStream(fos);  
            fos.close();  
        }  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:29,代码来源:Docx4j_SaveDocxImg_S3_Test.java

示例3: main

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	
	
	// 加载模板
	InputStream template = HtmlToDOCDemo.class.getResourceAsStream("kcjj.xml");
	WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(template);
	PhysicalFontUtils.setSimSunFont(wordMLPackage);
	// 加载Html数据
	String jxdg = IOUtils.toString(HtmlToDOCDemo.class.getResourceAsStream("data.txt"));
	Map<String, String> richTextMap = new HashMap<String, String>();
	richTextMap.put("jxdg", jxdg);

	replaceRichText(wordMLPackage, richTextMap);
	
	File file = new File("d://result4.docx");
	wordMLPackage.save(file);
	System.out.println("success");

}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:20,代码来源:HtmlToDOCDemo.java

示例4: mergeDocx

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public InputStream mergeDocx(final List<InputStream> streams)  throws Docx4JException, IOException {  
  
    WordprocessingMLPackage target = null;  
    final File generated = File.createTempFile("generated", ".docx");  
  
    int chunkId = 0;  
    Iterator<InputStream> it = streams.iterator();  
    while (it.hasNext()) {  
        InputStream is = it.next();  
        if (is != null) {  
            if (target == null) {  
                // Copy first (master) document   
                OutputStream os = new FileOutputStream(generated);  
                os.write(IOUtils.toByteArray(is));  
                os.close();  
  
                target = WordprocessingMLPackage.load(generated);  
            } else {  
                // Attach the others (Alternative input parts)   
                insertDocx(target.getMainDocumentPart(),  
                        IOUtils.toByteArray(is), chunkId++);  
            }  
        }  
    }  
  
    if (target != null) {  
        target.save(generated);  
        return new FileInputStream(generated);  
    } else {  
        return null;  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:33,代码来源:Docx4jUtils.java

示例5: mergeDocx

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public static InputStream mergeDocx(final List<InputStream> streams)  throws Docx4JException, IOException {  
  
    WordprocessingMLPackage target = null;  
    final File generated = File.createTempFile("generated", ".docx");  
  
    int chunkId = 0;  
    Iterator<InputStream> it = streams.iterator();  
    while (it.hasNext()) {  
        InputStream is = it.next();  
        if (is != null) {  
            if (target == null) {  
                // Copy first (master) document   
                OutputStream os = new FileOutputStream(generated);  
                os.write(IOUtils.toByteArray(is));  
                os.close();  
                target = WordprocessingMLPackage.load(generated);  
            } else {  
                // Attach the others (Alternative input parts)   
                insertDocx(target.getMainDocumentPart(),IOUtils.toByteArray(is), chunkId++);  
            }  
        }  
    }  
  
    if (target != null) {  
        target.save(generated);  
        return new FileInputStream(generated);  
    } else {  
        return null;  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:31,代码来源:WMLPackageUtils.java

示例6: writeToString

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public String writeToString(File docFile) throws IOException, Docx4JException {
	WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(docFile);
	StringBuilderWriter output = new StringBuilderWriter();
	try {
		this.writeToWriter(wmlPackage, output);
	} finally {
		IOUtils.closeQuietly(output);
	}
	return output.toString();
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:11,代码来源:WordprocessingMLTemplateWriter.java

示例7: extract

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public String extract(File inputfile) throws Exception {
	WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(inputfile);
	StringBuilderWriter output = new StringBuilderWriter();
	try {
		this.extract(wmlPackage, output);
	} finally {
		IOUtils.closeQuietly(output);
	}
	return output.toString();
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:11,代码来源:WordprocessingMLPackageExtractor.java

示例8: loadWordprocessingMLPackageWithPwd

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 * @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;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:11,代码来源:Docx4j_工具类_S3_Test.java

示例9: loadWordprocessingMLPackage

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 * @Description:加载WordprocessingMLPackage
 */
public WordprocessingMLPackage loadWordprocessingMLPackage(String filePath)
        throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
            .load(new java.io.File(filePath));
    return wordMLPackage;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:10,代码来源:Docx4j_工具类_S3_Test.java

示例10: name

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public static void name() {
  
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));  
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();  
    String titleStr = "测试插入段落";  
    P p = Docx4j_Helper.factory.createP();  
    String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>";  
    RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr);  
    setParagraphContent(p, rpr, titleStr);  
    documentPart.getContent().add(5, p);  
      
    String tblPrStr = "<w:tblPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:tblW w:w=\"8522\" w:type=\"dxa\"/><w:tblBorders><w:top w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:left w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:bottom w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:right w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/><w:insideH w:val=\"single\"  w:sz=\"4\" w:space=\"0\"/></w:tblBorders></w:tblPr>";  
    Tbl tbl = Docx4j_Helper.factory.createTbl();  
    TblPr tblPr = (TblPr) XmlUtils.unmarshalString(tblPrStr);  
    tbl.setTblPr(tblPr);  
    Tr tr = Docx4j_Helper.factory.createTr();  
    Tc tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
    tbl.getContent().add(tr);  
      
    tr = Docx4j_Helper.factory.createTr();  
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
      
    tc = Docx4j_Helper.factory.createTc();  
    tr.getContent().add(tc);  
    tbl.getContent().add(tr);  
    documentPart.getContent().add(9, tbl);  
      
    Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:53,代码来源:Docx4j_Helper.java

示例11: unzipWord

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public void unzipWord(String fileName,String outFilePath) throws Exception {  
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage  
            .load(new java.io.File(fileName));  
    File baseDir = new File(outFilePath);  
    baseDir.mkdir();  
    UnzippedPartStore ups = new UnzippedPartStore(baseDir);  
    ups.setSourcePartStore(wordMLPackage.getSourcePartStore());  
    Save saver = new Save(wordMLPackage, ups);  
    saver.save(null);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:11,代码来源:Word_解压_Unzip_S3_Test2.java

示例12: removeAllComment

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
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));  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:32,代码来源:Docx4j_删除所有批注_S3_Test.java

示例13: unzipWord

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public void unzipWord(String fileName,String outFilePath) throws Exception {   
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(fileName));   
    File baseDir = new File(outFilePath);   
    baseDir.mkdir();   
    UnzippedPartStore ups = new UnzippedPartStore(baseDir);   
    ups.setSourcePartStore(wordMLPackage.getSourcePartStore());   
    Save saver = new Save(wordMLPackage, ups);   
    saver.save(null);   
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:10,代码来源:Word_解压_Unzip_S3_Test.java

示例14: process

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
@Override
public WordprocessingMLPackage process(Map<String, Object> variables) throws Exception {
	//初始化参数
	configuration();
	/*
	WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(sourceDocx);
	MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();  
       //获取静态变量集合
       HashMap<String, String> staticMap = getStaticData(variables);
       // 替换普通变量  
       documentPart.variableReplace(staticMap);  
       */
	//解压文档到指定的临时目录
	WmlZipUtils.unzip(this.sourceDocx, this.unzipDir);
	//加载主要文件
	File contentXmlFile = new File(this.unzipDir, PATH_TO_CONTENT);
	if (!contentXmlFile.exists()) {
		throw new FileNotFoundException(contentXmlFile.getAbsolutePath());
	}
	//进行变量替换
	String template = FileUtils.readFileToString(contentXmlFile, this.inputEncoding );
	for (Map.Entry<String, Object> entry : variables.entrySet()) {
		//替换变量
		template = StringUtils.replace(template, this.placeholderStart + entry.getKey() + this.placeholderEnd, String.valueOf(entry.getValue()));
	}
	/*if(this.sourceDel){
		//删除源文件
		this.sourceDocx.delete();
	}*/
	//创建临时目录
	String sourceDocxPath = this.sourceDocx.getPath();
	String tempDocxPath = sourceDocxPath.substring(0, sourceDocxPath.lastIndexOf(".")) + "_bak";
	File tempDir = new File(tempDocxPath);
	//清空临时目录
	FileUtils.deleteDirectory(tempDir);
	//拷贝解压的文件目录到指定的文件目录
	FileUtils.copyDirectory(this.unzipDir, tempDir);
	//将处理后的主文档文件写到临时目录
	FileUtils.writeStringToFile(new File(tempDir, PATH_TO_CONTENT), template, this.outputEncoding );
	//把临时目录压缩为一个文件,且地址为源文件地址,以便替换掉源文件
	WmlZipUtils.zipDir(tempDir, this.outputDocx, false);
	//删除临时目录
	FileUtils.deleteDirectory(tempDir);
       //返回WordprocessingMLPackage对象
	return WordprocessingMLPackage.load(this.outputDocx);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:47,代码来源:WordprocessingMLDocxTemplate.java

示例15: getWMLPackageTemplate

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 * 首先,我们创建一个可用作模版的简单的word文档。对于此只需打开Word,创建新文档然后保存为template.docx,这就是我们将要用于添加内容的word文档。
 * 我们需要做的第一件事是使用docx4j将这个文档加载进来,你可以使用下面的几行代码做这件事:
 */
public static WordprocessingMLPackage getWMLPackageTemplate(String filepath) throws Docx4JException, FileNotFoundException {
	WordprocessingMLPackage template = WordprocessingMLPackage.load(new FileInputStream(new File(filepath)));
	return template;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:9,代码来源:WMLPackageUtils.java


注:本文中的org.docx4j.openpackaging.packages.WordprocessingMLPackage.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。