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


Java WordprocessingMLPackage.save方法代码示例

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


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

示例1: main

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    //创建一个word
    //读取可以使用WordprocessingMLPackage.load方法
    WordprocessingMLPackage word = WordprocessingMLPackage.createPackage();
    String imageFilePath = Docx4jTest.class.getResource("/lw.jpg").getPath();

    //创建页眉
    HeaderPart headerPart = createHeader(word);
    //页眉添加图片
    headerPart.getContent().add(newImage(word, headerPart, imageFilePath));

    //创建页脚
    FooterPart footerPart = createFooter(word);
    //添加图片
    footerPart.getContent().add(newImage(word, footerPart, imageFilePath));

    //主内容添加文本和图片
    word.getMainDocumentPart().getContent().add(newText("http://www.mybatis.tk"));
    word.getMainDocumentPart().getContent().add(newText("http://blog.csdn.net/isea533"));

    word.getMainDocumentPart().getContent().add(
            newImage(word, word.getMainDocumentPart(), imageFilePath));

    //保存
    word.save(new File("d:/1.docx"));
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:27,代码来源:Docx4jTest.java

示例2: 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

示例3: convertToDocx

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public void convertToDocx(String markdown, File file) throws Docx4JException, JAXBException {
    WordprocessingMLPackage wordMLPackage;
    wordMLPackage = WordprocessingMLPackage.createPackage();
    NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
    wordMLPackage.getMainDocumentPart().addTargetPart(ndp);
    ndp.unmarshalDefaultNumbering();
    XHTMLImporterImpl xHTMLImporter = new XHTMLImporterImpl(wordMLPackage);
    xHTMLImporter.setHyperlinkStyle("Hyperlink");
    // Must be a properly formatted html doc.. No fragments
    wordMLPackage.getMainDocumentPart().getContent().addAll(
            xHTMLImporter.convert(Utils.wrapWithHtmlDocType(convertToHTML(markdown)),
                    null)
    );
    wordMLPackage.save(file);
}
 
开发者ID:jdesive,项目名称:textmd,代码行数:16,代码来源:MarkdownParser.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: writeToDocx

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 * 将 {@link org.docx4j.openpackaging.packages.WordprocessingMLPackage} 存为 docx
 */
public void writeToDocx(WordprocessingMLPackage wmlPackage,OutputStream output) throws IOException, Docx4JException {
	Assert.notNull(wmlPackage, " wmlPackage is not specified!");
	Assert.notNull(output, " output is not specified!");
       try {
       	wmlPackage.save(output , Docx4J.FLAG_SAVE_ZIP_FILE );//保存到 docx 文件
	} finally{
		IOUtils.closeQuietly(output);
       }
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:13,代码来源:WordprocessingMLPackageWriter.java

示例7: testDocx4jCreateTable

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public void testDocx4jCreateTable() throws Exception {  
    boolean landscape = false;  
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage  
            .createPackage(PageSizePaper.A4, landscape);  
    ObjectFactory factory = Context.getWmlObjectFactory();  
    setPageMargins(wordMLPackage, factory);  
    String imgFilePath = "f:/saveFile/tmp/2sql日志.jpg";  
    Tbl table = createTableWithContent(wordMLPackage, factory, imgFilePath);  
    wordMLPackage.getMainDocumentPart().addObject(table);  
    wordMLPackage.save(new File("f:/saveFile/temp/sys_"  
            + System.currentTimeMillis() + ".docx"));  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:13,代码来源:Docx4j_创建表格_S5_Test.java

示例8: convertToWmlObject

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
private static List<Object> convertToWmlObject(
		WordprocessingMLPackage wordMLPackage, String content)
		throws Docx4JException, JAXBException {
	MainDocumentPart document = wordMLPackage.getMainDocumentPart();
	//获取Jsoup参数
	String charsetName = Docx4jProperties.getProperty(Docx4jConstants.DOCX4J_CONVERT_OUT_WMLTEMPLATE_CHARSETNAME, Docx4jConstants.DEFAULT_CHARSETNAME );
	
	List<Object> wmlObjList = null;
	String templateString = XmlUtils.marshaltoString(document.getContents().getBody());
	System.out.println(templateString);
	Body templateBody = document.getContents().getBody();
	try {
		document.getContents().setBody(XmlUtils.deepCopy(templateBody));
		document.getContent().clear();
		Document doc = Jsoup.parse(content);
		doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml).escapeMode(Entities.EscapeMode.xhtml);
		//XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordMLPackage);
		
		AlternativeFormatInputPart  part = document.addAltChunk(AltChunkType.Xhtml,doc.html().getBytes(Charset.forName(charsetName)));
		
		WordprocessingMLPackage tempPackage = document.convertAltChunks();
		File file = new File("d://temp.docx");
		tempPackage.save(file);
		wmlObjList = document.getContent();
		//part.getOwningRelationshipPart().getSourceP().get
		//wmlObjList = xhtmlImporter.convert(doc.html(), doc.baseUri());
	} finally {
		document.getContents().setBody(templateBody);
	}
	return wmlObjList;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:32,代码来源:HtmlToDOCDemo.java

示例9: 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

示例10: main

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 *  首先我们创建对象工厂和包并从包中抽出文档部件. 然后我们添加目录表, 后面跟着一些带有分类
 *  标题样式的段落. 最后我们保存包.
 */
public static void main(String[] args) throws Docx4JException {
    factory = Context.getWmlObjectFactory();
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
 
    addTableOfContent(documentPart);
 
    documentPart.addStyledParagraphOfText("Heading1", "Hello 1");
    documentPart.addStyledParagraphOfText("Heading2", "Hello 2");
    documentPart.addStyledParagraphOfText("Heading3", "Hello 3");
    documentPart.addStyledParagraphOfText("Heading1", "Hello 1");
 
    wordMLPackage.save(new File("src/main/files/HelloWord10.docx"));
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:19,代码来源:AddingTableOfContent.java

示例11: main

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 *  像往常一样, 我们创建了一个包(package)来容纳文档.
 *  然后我们创建了一个指向将要添加到文档的图片的文件对象.为了能够对图片做一些操作, 我们将它转换
 *  为字节数组. 最后我们将图片添加到包中并保存这个包(package).
 */
public static void main (String[] args) throws Exception {
    WordprocessingMLPackage  wordMLPackage = WordprocessingMLPackage.createPackage();
 
    File file = new File("src/main/resources/iProfsLogo.png");
    byte[] bytes = convertImageToByteArray(file);
    addImageToPackage(wordMLPackage, bytes);
 
    wordMLPackage.save(new java.io.File("src/main/files/HelloWord7.docx"));
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:15,代码来源:AddingAnInlineImage.java

示例12: writeDocxToStream

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public static void writeDocxToStream(WordprocessingMLPackage template, String target) throws IOException, Docx4JException {  
    File f = new File(target);  
    template.save(f);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:5,代码来源:WMLPackageUtils.java

示例13: saveWordPackage

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/**
 * @Description:保存WordprocessingMLPackage
 */
public void saveWordPackage(WordprocessingMLPackage wordPackage, File file)
        throws Exception {
    wordPackage.save(file);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:8,代码来源:Docx4j_工具类_S3_Test.java

示例14: saveWordPackage

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
/** 
 * 保存文档 
 */  
public static void saveWordPackage(WordprocessingMLPackage wordPackage, String filePath) throws Exception {  
    wordPackage.save(new File(filePath));  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:7,代码来源:Docx4j_替换模板.java

示例15: saveWordPackage

import org.docx4j.openpackaging.packages.WordprocessingMLPackage; //导入方法依赖的package包/类
public void saveWordPackage(WordprocessingMLPackage wordPackage, File file)
		throws Exception {
	wordPackage.save(file);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:5,代码来源:Docx4J_例子2.java


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