Skip to content
Julian Halliwell edited this page Sep 20, 2021 · 4 revisions

Adds an image to a spreadsheet print header.

setHeaderImage( workbook=workbook, position, image ); // file path
setHeaderImage( workbook=workbook, position, image, imageType ); // object

Required arguments

  • workbook spreadsheet object
  • position string where to place the image in the header. Possible values: left or l, center or centre or c, right or r
  • image EITHER string: absolute path to the image file, OR image object: a CFML image object
  • imageType (only required if image is a CFML image object): string: Possible values: dib, emf, jpeg, jpg, pict, png, wmf

Chainable? Yes.

Notes

  1. You can only add header and footer images to XLSX files (i.e. Microsoft's XML format).
  2. You cannot add header/footer images to an existing spreadsheet which already has one or more header/footer images.
  3. Images may only appear when using Microsoft Excel. They are not supported in LibreOffice or Google Sheets.

Example 1: Using an image file

spreadsheet = New spreadsheet();
workbook = spreadsheet.newXlsx();
spreadsheet.addRow( workbook, [ "a", "b", "c", "d", "e" ] );
imagePath = ExpandPath( "blue.jpg" );
spreadsheet.setHeaderImage( workbook, "centre", imagePath );
spreadsheet.setSheetTopMargin( workbook, 2 );
spreadsheet.write( workbook, ExpandPath( "text.xlsx" ), true );

Excel print preview showing header image

Example 2: Using an image object

spreadsheet = New spreadsheet();
workbook = spreadsheet.newXlsx();
spreadsheet.addRow( workbook, [ "a", "b", "c", "d", "e" ] );
imageObject = ImageRead( "https://docs.lucee.org/assets/images/lucee-logo-bw.png" );
spreadsheet.setHeaderImage( workbook, "left", imageObject , "png" );
spreadsheet.setSheetTopMargin( workbook, 3 );
spreadsheet.write( workbook, ExpandPath( "text.xlsx" ), true );

Excel print preview showing header image

Clone this wiki locally