SpreadsheetAddImage() not working

LEGEND ,
Nov 30, 2017 Nov 30, 2017

Copy link to clipboard

Copied

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,

^ _ ^

Views

285

Likes

Translate

Translate

Report

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

correct answers 1 Correct Answer

Adobe Community Professional , Dec 04, 2017 Dec 04, 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...

Likes

Translate

Translate
LEGEND ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

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

V/r,

^ _ ^

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 01, 2017 Dec 01, 2017

Copy link to clipboard

Copied

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 (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

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
LEGEND ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

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,

^ _ ^

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

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" />

Likes

Translate

Translate

Report

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
LEGEND ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

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

V/r,

^ _ ^

Likes

Translate

Translate

Report

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
LEGEND ,
Dec 04, 2017 Dec 04, 2017

Copy link to clipboard

Copied

LATEST

You nailed it, BKBK.  This tag is (IMHO) not very intuitive.  I was trying to fit the image into just one cell, which apparently does not work.

I had to work with it and massage the numbers to finally get the image to appear in A:2.  (My OP had the coordinates wrong, too.)

This is what finally worked, for anyone else who might run across this.  To get the image to appear in first column, second row.

<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,3,2');

</cfscript>                              // ^^^^^^^

Now I just have to get the width/height of the cell right (this works, but it forces the image to be the size of the cell, and 75 x 75 is too big, in Excel.)

Thanks, BKBK!

V/r,

^ _ ^

Likes

Translate

Translate

Report

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