Skip to main content
dar formato al código.
Origen Enlace

EsteMe paso lo mismo que a ti cuando no puse esto:

pict.resize();

Si no sirve eso puedes usar,este método te permite agregar una imagen en la columna 0 fila 0.

    protected void addImage(Sheet sheet, BufferedImage img) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, ".png", baos);
    baos.flush();
    byte[] imageInByte = baos.toByteArray();
    baos.close();
    //Revisar si es png o jpg
    int pictureIdx = sheet.getWorkbook().addPicture(imageInByte, Workbook.PICTURE_TYPE_PNG);
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();
    Drawing<?> drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor = helper.createClientAnchor();
    anchor.setCol1(0);
    anchor.setRow1(0);

    Picture pict = drawing.createPicture(anchor, pictureIdx);
    pict.resize();
    }

Este método te permite agregar una imagen en la columna 0 fila 0.

    protected void addImage(Sheet sheet, BufferedImage img) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, ".png", baos);
    baos.flush();
    byte[] imageInByte = baos.toByteArray();
    baos.close();
    //Revisar si es png o jpg
    int pictureIdx = sheet.getWorkbook().addPicture(imageInByte, Workbook.PICTURE_TYPE_PNG);
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();
    Drawing<?> drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor = helper.createClientAnchor();
    anchor.setCol1(0);
    anchor.setRow1(0);

    Picture pict = drawing.createPicture(anchor, pictureIdx);
    pict.resize();
    }

Me paso lo mismo que a ti cuando no puse esto:

pict.resize();

Si no sirve eso puedes usar,este método te permite agregar una imagen en la columna 0 fila 0.

    protected void addImage(Sheet sheet, BufferedImage img) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, ".png", baos);
    baos.flush();
    byte[] imageInByte = baos.toByteArray();
    baos.close();
    //Revisar si es png o jpg
    int pictureIdx = sheet.getWorkbook().addPicture(imageInByte, Workbook.PICTURE_TYPE_PNG);
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();
    Drawing<?> drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor = helper.createClientAnchor();
    anchor.setCol1(0);
    anchor.setRow1(0);

    Picture pict = drawing.createPicture(anchor, pictureIdx);
    pict.resize();
    }
Origen Enlace

Este método te permite agregar una imagen en la columna 0 fila 0.

    protected void addImage(Sheet sheet, BufferedImage img) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(img, ".png", baos);
    baos.flush();
    byte[] imageInByte = baos.toByteArray();
    baos.close();
    //Revisar si es png o jpg
    int pictureIdx = sheet.getWorkbook().addPicture(imageInByte, Workbook.PICTURE_TYPE_PNG);
    CreationHelper helper = sheet.getWorkbook().getCreationHelper();
    Drawing<?> drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor = helper.createClientAnchor();
    anchor.setCol1(0);
    anchor.setRow1(0);

    Picture pict = drawing.createPicture(anchor, pictureIdx);
    pict.resize();
    }