addSheet

addSheet

BASIC / ADVANCED / PREMIUM

Inserts a new sheet into the Excel spreadsheet.

Description
public addSheet($options = array())

This method allows the creation of new sheets in the Excel spreadsheet.

The name of the first sheet is set to 'Sheet1' in all XLSX files created from scratch. This name can be customized in the new CreateXlsx class:

Parameters

options

Key Type Description
active bool If true set as active sheet. Default as false.
color string HEX value.
name string Custom sheet name. Must be unique in the spreadsheet and it can't contain ':' '\' '/' '?' '*' '[' ']'. If this option is not set a default new name is generated automatically.
pageMargins array Keys and values:
  • left (float)
  • right (float)
  • top (float)
  • bottom (float)
  • header (float)
  • footer (float)
position int Sheet position. As default use the last position. 0 is the first sheet.
removeSelected bool If true remove selected property in all sheets. Default as false.
rtl bool Set to true for right to left.
selected bool If true set the new sheet as selected. Default as false.
state string hidden.
Exceptions

The sheet name exists.

Code samples

Example #1

The resulting XLSX looks like:

Example #2

The resulting XLSX looks like:

Example #3

The resulting XLSX looks like:

Example #4

The resulting XLSX looks like:

Release notes
  • phpxlsx 2.5:
    • position and color options.
  • phpxlsx 2.0:
    • state option.
  • phpxlsx 1.0:
    • new method.