Whatever message this page gives is out now! Go check it out!

SpreadsheetAddImage

Last update:
May 18, 2026
Note:
You can find the CFFiddle demo of this function and other spreadsheet functions as part of a project that is shared with you.
Click the button below to launch CFFiddle.
To copy the project in your workspace in CFFiddle, follow the steps below:
  1. Log in with your Gmail or Facebook credentials.
  2. Navigate to the project in the left pane.
  3. Once you make some changes in any cfm in the project, a pop up displays asking you to save the project.
  4. Give the project a suitable name and click Save.

Description

Adds an image to an Excel spreadsheet object.

Returns

Nothing

Syntax

SpreadsheetAddImage(spreadsheet,imagePath,anchor,imageData,imageType)

Category

History

ColdFusion (2018 release): Introduced named parameters.
ColdFusion 11: Added the function.

Parameters

Parameter
Description
spreadsheet
The Excel spreadsheet object to which to add the column.
anchor
The image location, as a comma delimited list in either of the following formats:
  • startRow,startColumn,endRow,endColumn
  • startXPosition,startYPosition,endXPosition,endYPositions,startRow,startColumn,endRow, endColumn 
imageData
A ColdFusion image object.
imageFilePath
The absolute path to the image file.
imageType
The image format, one of the following:
  • jpg or jpeg
  • png
  • dib

Example 1

The following example creates a PNG format chart, puts it in a new spreadsheet between (5,5) and (12,10), and writes the spreadsheet object to a file.
<cfchart format="png" scalefrom="-50" scaleTo="100" gridlines="5" name="myChart"> 
       <cfchartseries type="line"> 
             <cfchartdata item="Point1" value="-50"> 
             <cfchartdata item="Point2" value="-25"> 
             <cfchartdata item="Point3" value="1"> 
             <cfchartdata item="Point4" value="25"> 
             <cfchartdata item="Point5" value="50"> 
             <cfchartdata item="Point6" value="75"> 
             <cfchartdata item="Point7" value="99"> 
       </cfchartseries> 
</cfchart> 

<cfscript> 
       theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); 
       SpreadsheetObj=SpreadsheetNew(); 
       SpreadsheetAddImage(SpreadsheetObj,myChart,"png","5,5,12,10");
       SpreadSheetWrite(SpreadsheetObj,"#theDir#imagesheet.xls",true);
</cfscript>

Output

Figure: Line output
Line output

Example 2

The following example creates a PNG format series of random points on a 400x400 image and writes the image on a spreadsheet.
<cfscript>
       // Create a ColdFusion image of points
       myImage=ImageNew("",400,400,"rgb","lightgray");
       for (i=10;i<400;i++){
             ImageSetDrawingColor(myImage,"black");
             x=randRange(5,350);
             y=randRange(10,300);
             ImageDrawPoint(myImage,x,y);
       }
       // Add points to spreadsheet object and write to file
       theDir=GetDirectoryFromPath(GetCurrentTemplatePath()); 
       SpreadsheetObj=SpreadsheetNew(); 
       SpreadsheetAddImage(SpreadsheetObj,myImage,"png","5,5,12,10");
       SpreadSheetWrite(SpreadsheetObj,"#theDir#imagesheet1.xls",true);
</cfscript>

Output

Figure: Point output
Point output

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page