addTextBox

addTextBox

BASIC / ADVANCED / PREMIUM

Inserts a text box into the Excel spreadsheet.

Description
public addTextBox($contents, $position, $textBoxStyles = array(), $options = array())

This method inserts text boxes into the Excel spreadsheet.

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.
highlight string Hexadecimal color value: 'FF0000', '000000'...
italic bool If true displays the content in italics.
strikethrough bool If true displays text in strikethrough.
transparency int 0 to 100.
underline string Underlines text: single, double.
  • a multidimensional array to add rich text contents

position

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

textBoxStyles

Key Type Description
align string left, center, right.
backgroundColor string Hexadecimal color value: 'FF0000', '000000'...
backgroundTransparency int 0 to 100.
border array
  • 'color' (string) FFFFFF, FF0000...
  • 'dashType' (string) solid, roundDot, squareDot, dash...
  • 'transparency' (int) 0 to 100.
  • 'width' (int) EMUs.
rotation int 60.000ths of a degree.
verticalAlign string top, middle, bottom.

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 text box.
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.
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 text box.
Code samples

Example #1

The resulting XLSX looks like:

Example #2

The resulting XLSX looks like:

Release notes
  • phpxlsx 5.5:
    • backgroundTransparency, border, rotation, transparency options.
    • extra check to preserve tag order when adding new drawing tags if legacy drawing tags already exist in the sheet.
  • phpxlsx 3.0:
    • new method.