0

I want to add image to the right side of Header in Excel in java using POI. Below is my sample code

private static void drawImageOnExcelSheet(XSSFSheet sheet, int row, int col, int height, int width, int pictureIdx)
        throws Exception {

    CreationHelper helper = sheet.getWorkbook().getCreationHelper();

    Drawing drawing = sheet.createDrawingPatriarch();

    ClientAnchor anchor1 = helper.createClientAnchor();
    anchor1.setAnchorType(AnchorType.DONT_MOVE_AND_RESIZE);

    anchor1.setRow2(row); // second anchor determines bottom right position
    anchor1.setCol2(col);
    anchor1.setDx2(Units.toEMU(width)); // dx = left + wanted width
    anchor1.setDy2(Units.toEMU(height)); // dy= top + wanted height

    Picture pic = drawing.createPicture(anchor1, pictureIdx);
    pic.resize();

}
shihabudheenk
  • 593
  • 5
  • 18
  • 2
    Please clarify your question. What is the problem using your code? The code puts a picture in sheets drawing which is over the cells of the sheet. But the sheet header part is not on sheets drawing but is on a `VMLDrawing` instead. You want to put the picture in sheet's header part and not over the cells? – Axel Richter Mar 15 '20 at 06:42

1 Answers1

3

I'm posting a stackoverflow reference in answer as i don't have privilege to comment.

See apache POI adding watermark in Excel workbook for how to set an image as header content in Excel

dilkushmp
  • 71
  • 2