Practical phpxlsx

Tables

Introduction

Tables allow inserting, grouping and managing a range of cells.

Additional options can be used to apply styles, customize column names, include functions and add filters.

Adding tables

The method for adding new tables in the active sheet is addTable:

This method includes the following parameters:

  • $contents: a multidimensional array with the contents and styles to be added
  • $position: cell position in the active sheet (A1, C3, AB7...)
  • $tableStyles: table styles
  • $options: column names, table name, totals, filters...

A very simple table can be created running:

Complex tables can be done, adding multiple columns, styles and total functions:

Tips and tricks

Table and column names are generated automatically. Custom names can be set in the $options parameter.

Table names must be unique.

The addTable method returns an array with the position range added.

Custom table styles can be generated using createTableStyle.

Next - Headers and footers