title: Include an image to the right of a cell in Excel in Java using POI
body: <p>Anyways wherein one can shift the image to the right of the cell in excel through java using poi. Tried all possible anchor position and co-ordinates but the image stays to the left side of the cell this </p>
  
  <p><img src="https://i.stack.imgur.com/8U2oR.png" alt="Actual"></p>
  
  <p>But required position is </p>
  
  <p><img src="https://i.stack.imgur.com/Hrug6.png" alt="Expected"></p>
  
  <p>Following is the code used to draw image to excel in java :-</p>
  
  <pre><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();
  
  }
  </code></pre>