poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 51455] It would be really nice to be able to set the background picture of a comment
Date Sun, 12 Aug 2012 11:30:01 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=51455

Evgeniy Berlog <superrubiroyd@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #1 from Evgeniy Berlog <superrubiroyd@gmail.com> ---
This problem should be fixed in trunk.

Please try with a nightly build - see download links on http://poi.apache.org/
or build yourself from SVN trunk, see http://poi.apache.org/subversion.html

Here is an example of code you can use to set backgroung image of comment:

public class Test {

    public static void main(String[] args) throws IOException {
        Workbook workbook = new HSSFWorkbook();
        Sheet sheetA = workbook.createSheet();

        int idx = loadPicture("test.png", (HSSFWorkbook) workbook);
        HSSFPatriarch patriarch = (HSSFPatriarch)
sheetA.createDrawingPatriarch();
        HSSFComment comment = patriarch.createCellComment(new
HSSFClientAnchor(0,0,0,0,(short)0,0,(short)10,10));
        comment.setString(new HSSFRichTextString("HSSF POI comment background
image"));
        comment.setBackgroundImage(idx);
        FileOutputStream fos = new
FileOutputStream("comment_backgroung_image.xls");
        workbook.write(fos);
        fos.close();
    }

    private static int loadPicture( String path, HSSFWorkbook wb ) throws
IOException
    {
        int pictureIndex;
        FileInputStream fis = null;
        ByteArrayOutputStream bos = null;
        try
        {
            fis = new FileInputStream( path);
            bos = new ByteArrayOutputStream( );
            int c;
            while ( (c = fis.read()) != -1)
                bos.write( c );
            pictureIndex = wb.addPicture( bos.toByteArray(),
HSSFWorkbook.PICTURE_TYPE_PNG );
        }
        finally
        {
            if (fis != null)
                fis.close();
            if (bos != null)
                bos.close();
        }
        return pictureIndex;
    }
}

-- 
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