[转载]利用echarts将图片写入excel中
参考博客:点击跳转
使用poi-3.10.1版本jar包
参考博客中代码写了一个测试,发现可行
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
String path = "D:\\tmp\\融合人脸模板.jpg";
ByteArrayOutputStream os = new ByteArrayOutputStream();
BufferedImage bufferedImage = ImageIO.read(new File(path));
ImageIO.write(bufferedImage,"PNG",os);
HSSFWorkbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("test");
HSSFPatriarch hp = (HSSFPatriarch) sheet.createDrawingPatriarch();
HSSFClientAnchor hca = new HSSFClientAnchor(5,5,5,5,(short)0,1,(short)5,26);
hp.createPicture(hca,wb.addPicture(os.toByteArray(),HSSFWorkbook.PICTURE_TYPE_PNG));
String outPath = "D:\\tmp\\test.xlsx";
FileOutputStream fos = new FileOutputStream(outPath);
wb.write(fos);
fos.flush();
fos.close();
最后实验结果如下,将图片放在了excel中
弄这个主要是公司为了生成报表,报表里面有一些图表要写入到excel中,并不仅仅是生成表格数据。