Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

310
Visualizações
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

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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();
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda