POI的操作Excel时,不可避免有操作图片的处理。怎么插入图片呢?网上也有不少介绍。
下面的代码是向Excel中插入多张图片的例子:
- public static void main(String[] args) {
- FileOutputStream fileOut = null;
- BufferedImage bufferImg = null;
- BufferedImage bufferImg1 = null;
- try {
- // 先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
- // 读入图片1
- ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
- bufferImg = ImageIO.read(new File("d:\\test11.jpg"));
- ImageIO.write(bufferImg, "jpg", byteArrayOut);
- // 读入图片2
- ByteArrayOutputStream byteArrayOut1 = new By