1

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.

4

1 回答 1

4

anchor我运行了您的代码,发现尺寸太小时图像没有出现。(我也使用SpreadSheetReadBinary而不是将电子表格写入磁盘,但这应该没有任何区别)。试试文档中的这个例子。如果图像可见,则表明尺寸存在问题。要修复它,您可以增加锚点尺寸或使用图像功能来减小图像的大小。

<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)#">
于 2013-07-18T22:03:30.013 回答