Coldfusion SpreadsheetAddImage function does not insert image

1k views Asked by At

I am currently on CF version 9.0.1 and I'm having trouble getting the SpreadsheetAddImage function to properly insert an image into the spreadsheet that I am generating. I'm not getting any error message, its just that the image does not display in the spreadsheet. I've also ruled out any issues with finding the image or returning it (tested by using cfimage writetobrowser attribute).

I also stripped out all of my data and formatting from the spreadsheet to rule out anything overwriting that cell's contents. Just to see if I could get a blank spreadsheet with an image.

See sample code below.

<cfset sObj = SpreadsheetNew()>
<!--- <cfimage source="pathtomyimage.jpg" name="image"> --->
<cfset image_var = ImageRead("pathtomyimage.png")>

<cfset SpreadsheetAddRow(sObj, "")>
<cfset SpreadsheetAddImage(sObj,image_var,"png","1,1,1,1")>

...

<cffile action="readbinary" file="#dest_loc#" variable="export_file">
<cffile action="delete" file="#dest_loc#">

<cfheader name="Content-Disposition" value="inline; filename=#file_name#.xls">
<cfcontent type="application/vnd.msexcel" variable="#toBinary(export_file)#">

I appreciate any feedback. Thanks.

1

There are 1 answers

4
Leigh On BEST ANSWER

I ran your code and found the image did not appear when the anchor dimensions were too small. (I also used SpreadSheetReadBinary instead of writing the spreadsheet to disk, but that should not make any difference). Try this example from the documentation. If the image is visible, that suggests a problem with the dimensions. To fix it you could either increase the anchor dimensions or use image functions to reduce the size of your image.

<cfchart format="png" name="image_var"> 
    <cfchartseries type="line"> 
        <cfchartdata item="Point1" value="-50"> 
        <cfchartdata item="Point2" value="-25"> 
        <cfchartdata item="Point3" value="1"> 
    </cfchartseries> 
</cfchart> 

<cfset sObj = SpreadsheetNew()>
<cfset SpreadsheetAddRow(sObj, "")>
<cfset SpreadsheetAddImage(sObj,image_var,"png","1,1,7,6")>
<cfheader name="Content-Disposition" value="inline; filename=testFile.xls">
<cfcontent type="application/vnd.msexcel" variable="#SpreadSheetReadBinary(sObj)#">