Learn phpxlsx in 5 minutes

Quickstart guide

Information

phpxlsx is the most comprehensive library for working with XLSX spreadsheets. It comprises all the necessary methods to generate new spreadsheets, customize templates, insert and modify contents, define and apply styles, transform formats such as HTML and CSS, convert to PDF, encrypt, digitally sign and many other functionalities.

All available methods are very easy to use, and they allow to perform effortlessly any task, from the simplest to the most complex one.

Creating new spreadsheets

The CreateXlsx class generates a new XLSX in which to add contents.

The following example creates a new spreadsheet with a cell content and saves the XLSX to the file system:

Almost any MS Excel content can be added with phpxlsx. That includes images, tables, charts, headers, footers, comments...

When including the CreateXlsx.php file, the phpxlsx internal Autoloader is automatically loaded in order to access all the available classes.

Advanced and Premium licences come with a PHP namespaces package, not available in the Trial one.

Working with templates

Instead of generating a spreadsheet from scratch, it is possible to do it with MS Excel, LibreOffice, Google Docs or any other program in order to create an XLSX in which to include placeholders and other contents. phpxlsx counts with the necessary methods to replace those placeholders with new contents using the CreateXlsxFromTemplate class.

The following example opens an XLSX template, replaces the NAME placeholder with a new text and then saves the XLSX to the file system:

phpxlsx offers methods to replace placeholders in texts and images, and to get and remove placeholders.

By default, placeholders are defined by the $ symbol, which can be customized with others such as ${ }, #...

HTML and CSS

One of the most widely used features of phpxlsx is HTML and CSS to Excel conversion. It is a really easy way of adding contents to spreadsheets.

E.g., in order to add a paragraph with styles:

PDF and other document formats

Advanced and Premium licenses include the conversion plugin to transform XLSX to PDF, XLS to XLSX, and other conversions.

The transformDocument method is the responsible of the task. E.g., this transforms an XLSX created from scratch with phpxlsx or with templates, to PDF:

For more information

Besides this brief guide, we recommend visiting the following pages to understand phpxlsx in depth: