Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!