通过poi下载图片到word
一、添加相关依赖包
修改pom.xml文件,添加如下依赖(其他方式亦可)
二、实现方法
实现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
浙公网安备 33010602011771号