Has anyone been successful creating an Excel document with an
embedded image using POI HSSF?
Create a nicely formatted Excel is no, problem - but I can't
seem to figure the image part out. I am not calling the loadPicture
correctly, which is confusing CF.
/t5/coldfusion-discussions/inserting-an-image-in-excel-with-poi-hssf/m-p/192061#M17365Aug 01, 2008
Aug 01, 2008
Copy link to clipboard
Copied
MinOP wrote:
> but I can't seem to figure the image part out. I am not
calling the loadPicture correctly, which is confusing CF.
You did not mention which version of POI. Did you verify your
version supports the patriarch.createPicture method? If you are
using a really old version it might not.
Does the code actually have access to a loadPicture() method
or function? I think loadPicture() is a private method in one of
the example classes: org.apache.poi.hssf.usermodel.examples.*. So
you may have to write your own version of it. Assuming you have not
done so already...
I found the source code for the loadPicture method in svn and
adapted it to CF. Here is a working example. It creates a new
workbook, adds an image, and saves the file to disk.
A few notes about the code snippet. The code uses the
JavaLoader.cfc
JavaLoader.cfc to load a
newer version of the POI jar. The loadPicture function assumes the
image is .png format. Adapt it as needed.
I was hoping to utilize the POI that is deployed with CF 8. I
noticed on your blog that the POI deployed with CF may be only a
partial version of 2.5.1. This version does not seem to have
addPicture method for HSSFWorkbook?
morecarl wrote:
> This version does not seem to have addPicture method for
HSSFWorkbook?
You are welcome. Yes, it does not appear to contain some of
the packages like HWPF (for Word documents). As far as
HSSFWorkbook.addPicture goes, it is probably just a version issue.
I
think addPicture was introduced after version 2.5.1.