• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

236
Vistas
how set excel cell size according to image orignal size?

XSSFSheet sheet = workbook.createSheet(String.valueOf(photoIndex));

    XSSFRow headerRow = sheet.createRow(0);
    
    XSSFHyperlink link = creationHelper.createHyperlink(HyperlinkType.DOCUMENT);
    XSSFCell cellHeader1 = headerRow.createCell(0);
    cellHeader1.setCellValue("< Back to Issue List");
    link.setAddress("'Issue List'!A1");
    link.setLabel("< Back to Issue List");
    cellHeader1.setHyperlink(link);
    cellHeader1.setCellStyle(numberFormatCellStyleWithHyperLink(workbook));
    
    int col = 0, rowIndex = 1;
    for(String photosPath : serviceIssueDTO.getIssuePhotos()) {
        // Row for Photos
        XSSFRow row = sheet.createRow(rowIndex++);
        
        //FileInputStream obtains input bytes from the image file
        BufferedImage bimg = ImageIO.read(new File(GeneralPropertyAccessBean.imageUploadPath + photosPath));
        int width = bimg.getWidth();
        int height = bimg.getHeight();
        InputStream inputStream = new FileInputStream(GeneralPropertyAccessBean.imageUploadPath + photosPath);
        //Get the contents of an InputStream as a byte[].
        byte[] bytes = IOUtils.toByteArray(inputStream);
        //Adds a picture to the workbook
        int pictureIdx = workbook.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);
        //close the input stream
        inputStream.close();
        //Creates the top-level drawing patriarch.
        XSSFDrawing drawing = sheet.createDrawingPatriarch();
        //Create an anchor that is attached to the worksheet
        XSSFClientAnchor anchor = creationHelper.createClientAnchor();
        
        //create an anchor with upper left cell _and_ bottom right cell
        
        anchor.setCol1(col); //Column A
        anchor.setRow1(row.getRowNum()); //Row 1
        anchor.setCol2(col+1); //Column B
        anchor.setRow2(row.getRowNum()+1); //Row 2
        //Creates a picture
        XSSFPicture pict = drawing.createPicture(anchor, pictureIdx);
        
        row.createCell(col);

        sheet.setColumnWidth(col,(63*256));
        row.setHeightInPoint[enter image description here][1]s(height);

    }

I cant set a excel cell width and height according to image original width and height I set sheet.resize() but cant work also set sheet.autosizeColumn() but cant work

about 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You don't set a high-level height and width image in the particular cell if you want to set image original height and width so you can draw image on excel not set image in cell

for(String photosPath:serviceIssueDTO.getIssuePhotos())
{
    
    //FileInputStream obtains input bytes from the image file
    InputStream inputStream = new FileInputStream(GeneralPropertyAccessBean.imageUploadPath + photosPath);
    //Get the contents of an InputStream as a byte[].
    byte[] bytes = IOUtils.toByteArray(inputStream);
    //Adds a picture to the workbook
    int pictureIdx = workbook.addPicture(bytes, XSSFWorkbook.PICTURE_TYPE_JPEG);
    //close the input stream
    inputStream.close();
    //Creates the top-level drawing patriarch.
    XSSFDrawing drawing = sheet.createDrawingPatriarch();

    //Creates a picture
     XSSFClientAnchor my_anchor = new XSSFClientAnchor();
     my_anchor.setCol1(0);
     my_anchor.setRow1(row);
    XSSFPicture pict = drawing.createPicture(my_anchor, pictureIdx);
    
    row = (int) (row + Math.ceil(pict.getImageDimension().height/20) + 3);
    pict.resize();
}
about 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda