Working with images

To add, edit or remove images you should use IDrawingContent - service to manage spreadsheet graphic content

IDrawingContent depends on IWorksheetContent. To add an image, call the addImage() method with IDrawingInputBuilder:

Usage example

public class ImageExample {
    //...
    public void run() {
        ISpreadsheetApiProvider apiProvider = this.apiResolver.resolve(ISpreadsheetApiProvider.class);
        IWorkbook workbook = apiProvider.createNew().join();
        workbook.all().findFirst().ifPresent(worksheet -> {
            
            IDrawingService drawingService = worksheet.getContent().getDrawingContent().getImageService();

            byte[] imageRaw;
            try {
                imageRaw = IOUtils.toByteArray(this.getClass().getResourceAsStream("/test.jpg"));
            } catch (IOException e) {
                this.logger.error("Image content read error", e);
                return;
            }

            drawingService.addImage(                                    
                    this.apiResolver.resolve(IDrawingInputBuilder.class)  // default start anchor cell - A1
                            .setContent(imageRaw)                         // set image content
                            .setToSingleCell(true)                        // add images into single cell
                            .build());

            drawingService.addImage(                                    
                    this.apiResolver.resolve(IDrawingInputBuilder.class)
                            .fromCell(3, 3)                                // set start anchor cell
                            .fromCellWithOffset(2, 3)                      // set start anchor cell offset, points
                            .setDesiredWidth(345)                          // decrease image's size
                            .setDesiredHeight(460.5)                    
                            .setContent(imageRaw)                       
        });                 .build());
        
        workbook.createWriter().fileName("imageExample").save().join();
    }
}