poi导出word[1]

   
需要jar包
poi导出word[1]


  1. package util;  
  2.   
  3. import java.io.IOException;    
  4. import java.io.InputStream;    
  5.     
  6. import org.apache.poi.openxml4j.opc.OPCPackage;    
  7. import org.apache.poi.xwpf.usermodel.XWPFDocument;    
  8. import org.apache.xmlbeans.XmlException;    
  9. import org.apache.xmlbeans.XmlToken;    
  10. import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;    
  11. import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;    
  12. import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;    
  13.     
  14.     
  15. public class CustomXWPFDocument extends XWPFDocument    
  16.     public CustomXWPFDocument(InputStream in) throws IOException    
  17.         super(in);    
  18.        
  19.     
  20.         
  21.     public CustomXWPFDocument()    
  22.         super();    
  23.         // TODO Auto-generated constructor stub     
  24.        
  25.     
  26.         
  27.     public CustomXWPFDocument(OPCPackage pkg) throws IOException    
  28.         super(pkg);    
  29.         // TODO Auto-generated constructor stub     
  30.        
  31.     
  32.     public void createPicture(int id, int width, int height)    
  33.         final int EMU 9525   
  34.         width *= EMU;    
  35.         height *= EMU;    
  36.         String blipId getAllPictures().get(id).getPackageRelationship()    
  37.                 .getId();    
  38.     
  39.         CTInline inline createParagraph().createRun().getCTR()    
  40.                 .addNewDrawing().addNewInline();    
  41.     
  42.         String picXml ""    
  43.                 ""    
  44.                   "    
  45.                      "    
  46.                         "                
  47.                 id    
  48.                 "\" name=\"Generated\"/>"    
  49.                            "    
  50.                         "    
  51.                         "    
  52.                                
  53.                 blipId    
  54.                 "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>"    
  55.                            "    
  56.                               "    
  57.                            "    
  58.                         "    
  59.                         "    
  60.                            "    
  61.                               "    
  62.                                   
  63.                 width    
  64.                 "\" cy=\""    
  65.                 height    
  66.                 "\"/>"    
  67.                            "    
  68.                            "    
  69.                               "    
  70.                            "    
  71.                         "    
  72.                      "    
  73.                   " ""   
  74.     
  75.         // CTGraphicalObjectData graphicData     
  76.         inline.addNewGraphic().addNewGraphicData();    
  77.         XmlToken xmlToken null   
  78.         try    
  79.             xmlToken XmlToken.Factory.parse(picXml);    
  80.         catch (XmlException xe)    
  81.             xe.printStackTrace();    
  82.            
  83.         inline.set(xmlToken);    
  84.         // graphicData.set(xmlToken);     
  85.     
  86.         inline.setDistT(0);    
  87.         inline.setDistB(0);    
  88.         inline.setDistL(0);    
  89.         inline.setDistR(0);    
  90.     
  91.         CTPositiveSize2D extent inline.addNewExtent();    
  92.         extent.setCx(width);    
  93.         extent.setCy(height);    
  94.     
  95.         CTNonVisualDrawingProps docPr inline.addNewDocPr();    
  96.         docPr.setId(id);    
  97.         docPr.setName("图片" id);    
  98.         docPr.setDescr("现场监理图片");    
  99.        
  100.    
  101.   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值