赞
踩
- XSSFDrawing patriarch = sheet.createDrawingPatriarch();
- XSSFClientAnchor anchor = new XSSFClientAnchor(起始X偏移量, 起始Y偏移量, 结束X偏移量, 结束Y偏移量, 起始列,起始行,结束列, 结束行);
- // 设置图片不随列宽的变化而变化
- anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);
- // 插入图片
- patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
-
-
- // 其中
- byteArrayOut = getByteArrayOutputStream("图片路径")
-
-
- // getByteArrayOutputStream 函数
- public static ByteArrayOutputStream getByteArrayOutputStream(String path) throws IOException {
- InputStream inputStream = new FileInputStream(new File(path));
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int len;
- while ((len = inputStream.read(buffer)) != -1 ) {
- baos.write(buffer, 0, len);
- }
- baos.flush();
- return baos;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。