欢迎来到天天文库
浏览记录
ID:47102479
大小:18.26 KB
页数:11页
时间:2019-08-03
《poi操作word》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packagecom.haiyisoft.common.poi;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.Iterator;importjava.util.List;importjava.util.Map;im
2、portjava.util.Map.Entry;importorg.apache.poi.POIXMLDocument;importorg.apache.poi.openxml4j.exceptions.InvalidFormatException;importorg.apache.poi.xwpf.usermodel.ParagraphAlignment;importorg.apache.poi.xwpf.usermodel.XWPFDocument;importorg.apache.poi.xwpf.usermodel.XWPFParagraph;importorg.apa
3、che.poi.xwpf.usermodel.XWPFRun;importorg.apache.poi.xwpf.usermodel.XWPFTable;importorg.apache.poi.xwpf.usermodel.XWPFTableCell;importorg.apache.poi.xwpf.usermodel.XWPFTableRow;importorg.apache.xmlbeans.XmlException;importorg.apache.xmlbeans.XmlToken;importorg.openxmlformats.schemas.drawingml
4、.x2006.main.CTNonVisualDrawingProps;importorg.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;importorg.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;publicclassPoiWordTemplate{privateXWPFDocumentdocument;publicXWPFDocumentgetDocument(){returndocument;}pu
5、blicvoidsetDocument(StringtemplatePath){try{this.document=newXWPFDocument(POIXMLDocument.openPackage(templatePath));}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}//this.document=document;}/***往模板中插入图片*@paramdocument*@parammapImage*@paramwidth*@paramheight*/publicvoi
6、dreplaceTextToImage(MapmapImage,intwidth,intheight){ListlistParagraphs=this.document.getParagraphs();for(inti=0;ientry:mapImage.entrySet()){if(listParagraphs.get(i).getText().trim().indexOf(entry.getKey())!=-1)
7、{CTInlineinline=listParagraphs.get(i).createRun().getCTR().addNewDrawing().addNewInline();try{insertPicture(entry.getValue(),inline,width,height);}catch(InvalidFormatExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(FileNotFoundE
此文档下载收益归作者所有