Skip to main content
WolfShade
Legend
November 30, 2017
Answered

SpreadsheetAddImage() not working

  • November 30, 2017
  • 2 replies
  • 530 views

Hello, all,

I'm just playing around with something and wanted to see if I could insert an image into an Excel spreadsheet cell.  I found SpreadsheetAddImage(), and I'm not having any luck with it.  The image is a PNG file, 70 x 70 pixels in width and height.

<cfscript>

sObj = SpreadsheetNew("testing","true"); // This is for Excel 2013, not the older versions.

SpreadsheetSetCellValue(sObj,'Testing Image Insert',1,1);

SpreadsheetSetColumnWidth(sObj,1,75);

SpreadsheetSetRowHeight(sObj,2,75);

imgBytes = FileReadBinary("D:\site\images\emblem70x70.png");

SpreadsheetAddImage(sObj, imgBytes, 'png', '2,1,2,1');

<cfscript><cfheader name="Content-Disposition" value="attachment; filename=test.xlsx" />

<cfheader name="Content-Type" value="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#spreadsheetReadBinary(sObj)#" reset="true" />

When I open the spreadsheet, the text is in A:1 as expected, but the image does not appear in B:1.

Any thoughts about this appreciated.

V/r,

^ _ ^

This topic has been closed for replies.
Correct answer BKBK

Test with a different set of begin/end coordinates and headers

<cfscript> 

sObj = SpreadsheetNew("testing","true"); // This is for Excel 2013, not the older versions. 

SpreadsheetSetCellValue(sObj,'Testing Image Insert',1,1); 

SpreadsheetSetColumnWidth(sObj,1,75); 

SpreadsheetSetRowHeight(sObj,2,75); 

imgBytes = FileReadBinary("D:\site\images\emblem70x70.png"); 

SpreadsheetAddImage(sObj, imgBytes, 'png', '1,2,3,4'); 

</cfscript>

<cfheader name="Content-Disposition" value="attachment; filename=test.xlsx" /> 

<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#spreadsheetReadBinary(sObj)#" reset="true" />

2 replies

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
December 4, 2017

Test with a different set of begin/end coordinates and headers

<cfscript> 

sObj = SpreadsheetNew("testing","true"); // This is for Excel 2013, not the older versions. 

SpreadsheetSetCellValue(sObj,'Testing Image Insert',1,1); 

SpreadsheetSetColumnWidth(sObj,1,75); 

SpreadsheetSetRowHeight(sObj,2,75); 

imgBytes = FileReadBinary("D:\site\images\emblem70x70.png"); 

SpreadsheetAddImage(sObj, imgBytes, 'png', '1,2,3,4'); 

</cfscript>

<cfheader name="Content-Disposition" value="attachment; filename=test.xlsx" /> 

<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#spreadsheetReadBinary(sObj)#" reset="true" />

WolfShade
WolfShadeAuthor
Legend
December 4, 2017

Thank you, BKBK, I'll give that a shot and report back.

V/r,

^ _ ^

WolfShade
WolfShadeAuthor
Legend
December 1, 2017

I just noticed that I had typed the wrong filename for CFHEADER; I have corrected this.

V/r,

^ _ ^

Charlie Arehart
Community Expert
Community Expert
December 1, 2017

But you're not saying that solved the problem, right? Just that you caught the mistake in what you'd written here?

Assuming that's so, while I don't have an answer on the specific problem, I would ask ... like I would anyone :-) ... what is the CF version, and what update level? If not the latest, it could be a bug since fixed by Adobe. And even if the latest (or not), have you confirmed that there were no errors in the update log of the last CF update you did?

I realize it's unlikely that a bug or especially a problem in the update could lead to such a specific error as you see, but it's always best to check that first. :-)

/Charlie (troubleshooter, carehart. org)
WolfShade
WolfShadeAuthor
Legend
December 4, 2017

Ah!  I'm smacking my forehead.  I was so rushed that I completely forgot to include that information.

<sheepishgrin>D'oh!</sheepishgrin>

My development server is running CF 10:

version 10,0,20,299202, update 20

Tomcat v7.0.68.0

Win Server 2008 R2

Java 1.7.0_15

I will remote in to the server and check the install log of update 20.  I don't think there were any errors, but who knows.

And, yes, I corrected the filename, but have not found a solution for this issue.

V/r,

^ _ ^