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

spreadsheetSetHeaderImage

Last update:
May 18, 2026

Description

Adds an image to the header of a spreadsheet. The header image is visible on spreadsheet print preview.

Returns

None

History

  • ColdFusion (2025 release): Added the function.

Syntax

spreadsheetSetHeaderImage(spreadsheetObject, byte[] imageData, String alignment, String imageType) 

spreadsheetSetHeaderImage(spreadsheetObject,String image, String alignment)
Caution:
A sheet allows only one image in the header. Adding a second image when one is already present triggers an exception.

Parameters

Name
Required
Type
Description
spreadSheetObject
Yes
ExcelInfo
The Excel spreadsheet object to which to add the header image.
alignment
Yes
String
The image’s alignment in the header. The values are left, center, or right.
image
Yes
CFImage
A ColdFusion image object. The supported image formats are jpg/jpeg or png.

Example 1- using image object

<cfscript> 
    myImage=imageNew("",200,50) 
    imageSetDrawingColor(myImage,"yellow") 
    imageSetAntialiasing(myImage,"on") 
    imageDrawRect(myImage,80,25,50,30,"yes") 
</cfscript> 

<cfquery name="art" datasource="cfartgallery"> 
    SELECT * FROM ART 
</cfquery> 

<cfscript> 
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "art-header-object.xls"; 
    // create a spreadsheet object 
    theSheet=spreadsheetNew("SampleData",true) 
    // add rows from the table to the spreadsheet 
    spreadsheetAddRows(theSheet,art) 
    spreadsheetSetHeaderImage(spreadsheet = theSheet,  
                image = myImage,  
                alignment = 'center', 
                imagetype = 'png') 

    // write the spreadsheet 

    spreadsheetWrite(theSheet,theFile,"yes") 
</cfscript>

Example 1- using file path

<cfquery name="art" datasource="cfartgallery">
    SELECT * FROM ART
</cfquery>
<cfscript>
    theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "art-header-image.xls"
    theImage=GetDirectoryFromPath(GetCurrentTemplatePath()) &"Images/pngImage.png"
    // create a spreadsheet object
    theSheet=spreadsheetNew("SampleData",true)
    // add rows from the table to the spreadsheet
    spreadsheetAddRows(theSheet,art)
    spreadsheetSetHeaderImage(spreadsheet = theSheet, 
                image = theImage, 
                alignment = 'center')
    // write the spreadsheet
    spreadsheetWrite(theSheet,theFile,"yes")
</cfscript>

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