You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2011/07/01 12:41:51 UTC

DO NOT REPLY [Bug 51459] New: Image not added in HSSFWorkbook

https://issues.apache.org/bugzilla/show_bug.cgi?id=51459

             Bug #: 51459
           Summary: Image not added in HSSFWorkbook
           Product: POI
           Version: 3.8-dev
          Platform: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: martin.studer@mirai-solutions.com
    Classification: Unclassified


Created attachment 27235
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=27235
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.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 51459] Image not added in HSSFWorkbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51459

Nick Burch <ni...@alfresco.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX
         OS/Version|                            |All

--- Comment #2 from Nick Burch <ni...@alfresco.com> 2011-07-01 10:47:56 UTC ---
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...)

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


DO NOT REPLY [Bug 51459] Image not added in HSSFWorkbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=51459

--- Comment #1 from Martin Studer <ma...@mirai-solutions.com> 2011-07-01 10:42:31 UTC ---
Created attachment 27236
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=27236
Image file used for reproducing the issue

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org