poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 51459] New: Image not added in HSSFWorkbook
Date Fri, 01 Jul 2011 10:41:51 GMT
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


Mime
View raw message