addHeader

addHeader

BASIC / ADVANCED / PREMIUM

Adds a header into the Excel spreadsheet.

Description
public addHeader($contents, $target = 'default', $options = array())

This method adds headers into the Excel spreadsheet.

Parameters

contents

Array. Contents to be added.

Allowed positions: left, center, right.

Text content ('text' key):

  • 'bold' (bool)
  • 'color' (string): FFFFFF, FF0000...
  • 'font' (string): Arial, Times New Roman...
  • 'fontSize' (int): 8, 9, 10, 11...
  • 'italic' (bool)
  • 'strikethrough' (bool)
  • 'underline' (string): single, double.

Available special elements: &[Page], &[Pages], &[Date], &[Time], &[Tab], &[File], &[Path].

A multidimensional array can also be added to include texts with multiple styles.

Image content ('image' key):

  • 'src' (string): image path, base64 or stream.
  • 'alt' (string): alt text.
  • 'brightness' (string)
  • 'color' (string): automatic (default), grayscale, blackAndWhite, washout.
  • 'contrast' (string):.
  • 'height' (int): pt size.
  • 'title' (string): 'image' as default.
  • 'width' (int): pt size.

target

Array. Allowed values: first, default, even.

options

Key Type Description
replace bool If true replaces the existing footer if it exists. Default as true.
Exceptions

Image doesn't exist.

Image format is not supported.

Code samples

Example #1

The resulting XLSX looks like:

Example #2

The resulting XLSX looks like:

Release notes
  • phpxlsx 2.5: overwrite option renamed to replace.
  • phpxlsx 2.0: new method.