I'm trying to insert a logo in every sheet of excel below is the code snippet:
int numberOfSheets = wb.getNumberOfSheets();
for(int i=0;i<numberOfSheets;i++)
{
XSSFSheet sheet = wb.getSheetAt(i);
try {
//insert a logoS
String location = "/src/main/resources/logo/logo.jpg";
InputStream is = new FileInputStream(location);
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
CreationHelper creationHelper = wb.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = creationHelper.createClientAnchor();
anchor.setCol1(0);
anchor.setRow1(0);
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize(3.0,3.0);
} catch (FileNotFoundException e) {
log.info("Problem in reading logo.jpg");
} catch (IOException io) {
log.info("Problem in reading logo.jpg");
}
}
But in the result it does add an image in every sheet. I have 2 sheets in excel but the problem is when I click on 2nd sheet the image get stretched a little bit. I have resize it explicitly, if I dont put any number for resize then the stretched ratio is measurable.
What I can get from XSSFPicture Document
public void resize(double scaleX,double scaleY)
Resize the image relatively to its current size. Please note, that this method works correctly only for workbooks with the default font size (Calibri 11pt for .xlsx). If the default font is changed the resized image can be streched vertically or horizontally.
So my settings are also default as per stated above in