Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Inserting an Image in Excel with POI HSSF

New Here ,
Jul 31, 2008 Jul 31, 2008
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.

<cfset patriarch = newSheet.createDrawingPatriarch()/>
<cfset patriarch.createPicture(createObject("java",
"org.apache.poi.hssf.usermodel.HSSFClientAnchor").init(),
loadPicture("asset/images/logo_e2eA.png", workSheet))/>
TOPICS
Advanced techniques
3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 01, 2008 Aug 01, 2008
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.

> loadPicture("asset/images/logo_e2eA.png", workSheet))/>

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...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 01, 2008 Aug 01, 2008
MinOP,

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.





Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 03, 2008 Aug 03, 2008
MinOP,

I tweaked the code and here is a simplified version. The same notes apply: it requires the JavaLoader.cfc and assumes the image is .png format.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 04, 2008 Aug 04, 2008
Thanks for posting this - I've been struggling with this for a while. Can't wait to try it out.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 07, 2008 Aug 07, 2008
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?

Thanks for posting an alternate solution.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 07, 2008 Aug 07, 2008
LATEST
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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources