java poi导入图片问题

来源:互联网 发布:centos搜狗输入法安装 编辑:程序博客网 时间:2024/05/22 03:02
/**     * 工作薄对象     */    private SXSSFWorkbook wb;    /**     * 工作表对象     */    private Sheet sheet;    /**     * 样式列表     */    private Map<String, CellStyle> styles;    /**     * 当前行号     */    private int rownum;    private CreationHelper helper;      private Drawing drawing;      private ClientAnchor anchor;     private void drawPictureInfoExcel() {        this.wb = new SXSSFWorkbook(500);        this.sheet = wb.createSheet("Export");        this.styles = createStyles(wb);        this.drawing = sheet.createDrawingPatriarch();        this.helper = wb.getCreationHelper();         this.anchor = helper.createClientAnchor();        InputStream is = new FileInputStream(pictureId);                        byte[] bytes = IOUtils.toByteArray(is);            int pictureIdx= wb.addPicture(bytes, SXSSFWorkbook.PICTURE_TYPE_PNG);        // 图片插入坐标              anchor.setDx1(0);            anchor.setDy1(0);            anchor.setDx2(0);            anchor.setDy2(0);            anchor.setCol1(cellIndex);              anchor.setRow1(row.getRowNum());            anchor.setCol2(cellIndex+1);              anchor.setRow2(row.getRowNum()+1);            // 插入图片              Picture pict = drawing.createPicture(anchor, pictureIdx);             //pict.resize();//以原来图片大小的形式存放    }