通过poi下载图片到word

一、添加相关依赖包

修改pom.xml文件,添加如下依赖(其他方式亦可)


org.apache.poi
poi-ooxml
3.16


commons-codec
commons-codec



org.apache.poi
poi-scratchpad
3.16

二、实现方法

实现demo

XWPFDocument document = new XWPFDocument();

//获取本地图片 C:\Users\admin\Desktop
File file=new File("C:/Users/admin/Desktop/aa.jpg");
InputStream in = new FileInputStream(file);
BufferedImage image = ImageIO.read(file);

XWPFParagraph wparagraph = document.createParagraph();
XWPFRun wrun = wparagraph.createRun();
wrun.addPicture(in,
org.apache.poi.xwpf.usermodel.Document.PICTURE_TYPE_PNG, "",
Units.pixelToEMU(image.getWidth()),
Units.pixelToEMU(image.getHeight()));

 posted on 2018-06-25 11:19  AI.℡  阅读(280)  评论(0)    收藏  举报