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