setCellValue

setCellValue

BASIC / ADVANCED / PREMIUM

Adds cell contents into the Excel spreadsheet.

Description
public setCellValue($contents, $position)

This method allows adding cell values setting a position.

The same can be done using addCell, that allows using more options.

Parameters

contents

This could be:

  • a string
  • an array with the following keys and values:
Key Type Description
text string The content to be inserted.
bold bool If true the content will be shown in bold characters.
color string Hexadecimal color value: 'FF0000', '000000'...
font string Font family: 'Arial', 'Calibri'...
fontSize int Font size in points.
italic bool If true displays the content in italics.
strikethrough bool If true displays text in strikethrough.
subscript bool If true displays text in subscript.
superscript bool If true displays text in superscript.
underline string Underlines text: single, double.
  • a multidimensional array to add rich text contents

position

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

Code samples

Example #1

The resulting XLSX looks like:

Release notes
  • phpxlsx 2.5:
    • new method.