Created attachment 27235 [details] Excel file for reproducing the issue Trying to add an image to a worksheet does not actually work in the case of the attached Excel file (repro.xls). There is no error message - the image just won't end up on the worksheet. I could pin the problem down to the second worksheet (note, the image is to be added to first one). If I delete the second worksheet, it works. Originally, there were many more worksheets in the workbook and I tried deleting any of them in succession to detect where the issue is and it seems that exactly the remaining (worksheet 2 in repro.xls) is causing the grief. The following is the code to reproduce the issue: File f1 = new File("repro.xls"); File f2 = new File("earthquake.jpg"); HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(f1)); InputStream is = new FileInputStream(f2); byte[] bytes = IOUtils.toByteArray(is); int imageIndex = wb.addPicture(bytes, org.apache.poi.ss.usermodel.Workbook.PICTURE_TYPE_JPEG); is.close(); Name cname = wb.getName("Test"); Sheet sheet = wb.getSheet(cname.getSheetName()); AreaReference aref = new AreaReference(cname.getRefersToFormula()); CellReference topLeft = aref.getFirstCell(); CellReference bottomRight = aref.getLastCell(); Drawing drawing = null; drawing = ((HSSFSheet)sheet).getDrawingPatriarch(); if(drawing == null) { drawing = sheet.createDrawingPatriarch(); } CreationHelper helper = wb.getCreationHelper(); ClientAnchor anchor = helper.createClientAnchor(); anchor.setRow1(topLeft.getRow()); anchor.setCol1(topLeft.getCol()); anchor.setRow2(bottomRight.getRow() + 1); anchor.setCol2(bottomRight.getCol() + 1); anchor.setAnchorType(ClientAnchor.DONT_MOVE_AND_RESIZE); drawing.createPicture(anchor, imageIndex); FileOutputStream fos = new FileOutputStream(f1, false); wb.write(fos); fos.close(); I'm using POI 3.8-beta3 with a 64-bit JDK 1.6.0_20 on Windows 7 64-bit.
Created attachment 27236 [details] Image file used for reproducing the issue
You seem to be trying to add to an existing drawing patriarch, which doesn't work for hssf (except in a very small number of cases) If you want to add pictures, you need to start with a workbook with none in it, and then add them all in one go. See http://poi.apache.org/spreadsheet/quick-guide.html#Images (We'd love for HSSF to be able to edit existing pictures, but it's a massive amount of work and alas no-one has been willing so far to do it...)