0

I need to export pictures to excel in this way, what can I use to achieve this, is poi OK or is there a better solution.

private static void insertImagesToCell(Workbook workbook, Sheet sheet, Cell cell, String[] imageUrls) {

        CreationHelper helper = workbook.getCreationHelper();
        Drawing drawing = sheet.createDrawingPatriarch();

        for (String imageUrl : imageUrls) {
            if (imageUrl != null && !imageUrl.isEmpty()) {
                byte[] imageBytes = loadImage(imageUrl);
                int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG);
                imageBytes = null; // Clear the byte array

                ClientAnchor anchor = helper.createClientAnchor();
                anchor.setCol1(cell.getColumnIndex());
                anchor.setRow1(cell.getRowIndex());
//                anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
                Picture picture = drawing.createPicture(anchor, pictureIdx);
                picture.resize(0.7874,0.7874); // Resize the picture as needed
            }
        }
    }

I inserted the picture data into the cell this way, but the pictures kept overlapping and the picture size was strange

yi deng
  • 1
  • 2
  • Ok, there is no way to upload pictures, I want to export these picture data in the picture column in the same size of the cell sorted well, but I exported the pictures are overlapping, the size is not right – yi deng Aug 09 '23 at 13:33
  • https://stackoverflow.com/questions/33712621/how-put-a-image-in-a-cell-of-excel-java/33721090#33721090 – Axel Richter Aug 09 '23 at 16:57

0 Answers0