addImage

addImage

BASIC / ADVANCED / PREMIUM

Inserts an image into the Excel spreadsheet.

Description
public addImage($image, $position, $options = array())

This method inserts images (jpg, png, gif, bmp or webp) into the Excel spreadsheet.

Image size is set using rowSize and colSize options. If these values are not set, the image size is set to 1 column and 1 row.

Parameters

image

Image file path, base64, stream or GdImage.

position

Cell position in the active sheet: A1, C3, AB7...

options

Key Type Description
colOffset array
  • 'from' (int) column size offset from.
  • 'to' (int) column size offset to.
colSize int Number of columns used by the image.
descr string Descr value.
dpi int Dots per inch. Autodetect if not set.
editAs string Possible values are:
  • 'oneCell' (default) : move but don't size with cells.
  • 'twoCell' : move and size with cells.
  • 'absolute' : don't move or size with cells.
hyperlink string Hyperlink.
mime string Forces a mime (image/jpg, image/jpeg, image/png, image/gif, image/bmp, image/webp).
name string Sets a name value.
rowOffset array
  • 'from' (int) row size offset from.
  • 'to' (int) row size offset to.
rowSize int Number of rows used by the image.
Exceptions

Image doesn't exist.

Image format is not supported.

Code samples

Example #1

The resulting XLSX looks like:

Release notes
  • phpxlsx 4.0:
    • WebP images.
    • GdImage as image source.
  • phpxlsx 2.5:
    • stream and base64 as image source.
  • phpxlsx 2.0:
    • hyperlink option.
  • phpxlsx 1.0:
    • new method.