My use-case is to get the image of certain specified range.
Fro that, I am trying to copy that range from one workbook to to another and using SheetRender to get the desired the image. Following is the code snippet.
Range sourceRange = worksheet.getCells().createRange("A1:B4")
Workbook targetWorkbook = new Workbook(FileFormatType.XLSX);
Worksheet targetWs = targetWorkbook.getWorksheets().get(0);
Range targetRange = targetWs.getCells().createRange(0, 0, sourceRange.getRowCount(), sourceRange.getColumnCount());
PasteOptions options = new PasteOptions();
options.setPasteType(PasteType.ALL);
targetRange.copy(sourceRange, options);
Worksheet sheet = targetWorkbook.getWorksheets().get(0);
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions();
imgOptionsForTable.setImageFormat(resolvedImageFormat);
imgOptionsForTable.setHorizontalResolution(300);
imgOptionsForTable.setVerticalResolution(300);
imgOptionsForTable.setOnePagePerSheet(true);
imgOptionsForTable.setOnlyArea(true);
SheetRender sr = new SheetRender(sheet, imageOrPrintOptions);
sr.toImage(0, "C:/temp/abc.png");
I am able to get the image, however the image looses row sizes and does not render properly. Attached is the generated image and excel file for your reference. Kindly suggest what is going wrong.
Secondly, also suggest if there is some other better way to achieve this.