• 大小: 8.61MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-11-10
  • 语言: Java
  • 标签: POI  

资源简介

JAVA使用POI替换文本和图片,解决分割异常替换不完全的问题

资源截图

代码片段和文件信息

package com.scent.word;

import java.io.IOException;  
import java.io.InputStream;  
import org.apache.poi.openxml4j.opc.OPCPackage;  
import org.apache.poi.xwpf.usermodel.XWPFDocument;  
import org.apache.poi.xwpf.usermodel.XWPFParagraph;  
import org.apache.xmlbeans.xmlException;  
import org.apache.xmlbeans.xmlToken;  
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;  
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;  
import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;  
    
/** 
 * 自定义 XWPFDocument,并重写 createPicture()方法 
 */  
public class CustomXWPFDocument extends XWPFDocument {    

    public CustomXWPFDocument(InputStream in) throws IOException {    
        super(in);    
    }    
    
    public CustomXWPFDocument() {    
        super();    
    }    
    
    public CustomXWPFDocument(OPCPackage pkg) throws IOException {    
        super(pkg);    
    }    
    
    /** 
     * @param id 
     * @param width 宽 
     * @param height 高 
     * @param paragraph  段落 
     */  
    public void createPicture(int id int width int heightXWPFParagraph paragraph) {    
        final int EMU = 9525;    
        width *= EMU;    
        height *= EMU;    
        String blipId = getAllPictures().get(id).getPackageRelationship().getId();    
        CTInline inline = paragraph.createRun().getCTR().addNewDrawing().addNewInline();    
        String picxml = ““    
                + “lns:a=\“http://schemas.openxmlformats.org/drawingml/2006/main\“>“    
                + “   lformats.org/drawingml/2006/picture\“>“    
                + “      lns:pic=\“http://schemas.openxmlformats.org/drawingml/2006/picture\“>“    
                + “         “ + “                            + id    
                + “\“ name=\“Generated\“/>“    
                + “            “    
                + “         
“    
                + “         “    
                + “            bed=\““    
                + blipId    
                + “\“ xmlns:r=\“http://schemas.openxmlformats.org/officeDocument/2006/relationships\“/>“    
                + “            “    
                + “               “    
                + “            
“    
                + “         
“    
                + “         “    
                + “            “    
                + “               “    
                + “                               + width    
                + “\“ cy=\““    
                + height    
                + “\“/>“    
                + “            
“    
                + “            “    
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1035  2017-11-23 16:34  WordPrint\.classpath

     文件        385  2017-11-23 08:54  WordPrint\.project

     文件        598  2017-11-23 08:54  WordPrint\.settings\org.eclipse.jdt.core.prefs

     文件       5471  2017-11-23 16:43  WordPrint\bin\com\scent\word\CustomXWPFDocument.class

     文件       2101  2017-11-24 09:55  WordPrint\bin\com\scent\word\Test.class

     文件       7480  2017-11-24 09:53  WordPrint\bin\com\scent\word\WordUtil.class

     文件      52915  2017-01-10 05:19  WordPrint\lib\commons-logging-1.1.jar

     文件     313898  2017-01-10 05:19  WordPrint\lib\dom4j-1.6.1.jar

     文件      28592  2017-01-10 05:19  WordPrint\lib\geronimo-stax-api_1.0_spec-1.0.jar

     文件     121070  2017-01-10 05:19  WordPrint\lib\junit-3.8.1.jar

     文件     358180  2017-01-10 05:19  WordPrint\lib\log4j-1.2.13.jar

     文件    1675036  2017-01-10 05:19  WordPrint\lib\poi-3.7-20101029.jar

     文件     264108  2017-01-10 05:19  WordPrint\lib\poi-examples-3.7-20101029.jar

     文件     498259  2017-01-10 05:19  WordPrint\lib\poi-ooxml-3.7-20101029.jar

     文件    3967696  2017-01-10 05:19  WordPrint\lib\poi-ooxml-schemas-3.7-20101029.jar

     文件     840218  2017-01-10 05:19  WordPrint\lib\poi-scratchpad-3.7-20101029.jar

     文件    2666695  2017-01-10 05:19  WordPrint\lib\xmlbeans-2.3.0.jar

     文件       4075  2017-11-23 10:10  WordPrint\src\com\scent\word\CustomXWPFDocument.java

     文件       1565  2017-11-24 09:55  WordPrint\src\com\scent\word\Test.java

     文件       6851  2017-11-24 09:53  WordPrint\src\com\scent\word\WordUtil.java

     目录          0  2017-11-23 16:43  WordPrint\bin\com\scent\word

     目录          0  2017-11-24 09:57  WordPrint\src\com\scent\word

     目录          0  2017-11-23 16:43  WordPrint\bin\com\scent

     目录          0  2017-11-23 08:55  WordPrint\src\com\scent

     目录          0  2017-11-23 16:43  WordPrint\bin\com

     目录          0  2017-11-23 08:55  WordPrint\src\com

     目录          0  2017-11-23 08:54  WordPrint\.settings

     目录          0  2017-11-23 16:43  WordPrint\bin

     目录          0  2017-11-23 16:34  WordPrint\lib

     目录          0  2017-11-23 08:55  WordPrint\src

............此处省略4个文件信息

评论

共有 条评论