Skip to content →

Category: Introduction to PhpSpreadsheet

Reading data from a spreadsheet

Reading data from a spreadsheet can be done in multiple ways:

  1. Read a file using automatic file type detection
  2. Read a file by specifying the file type
  3. Read a file and opening specific worksheets
  4. Read a file in read-only mode
  5. Read a file and open only specific cells

How to read a file, by automatically detecting the file type

You should use this when you don’t know what file format the user will load.

How to read a file by specifying the file type:

This is faster than using the automatically detecting file type.

How to load only specific worksheets

How to open a file in read-only mode

How to read specific cells:

The following code will only read row 1 and rows 20 – 30 of any sheet in the Excel file:

Leave a Comment

How to install PhpSpreadsheet?

The simplest way of installing PHPSpreadSheet is to use Composer.

Here are the requirements for running this library:

  • PHP 5.6 (min version)
  • PHP extension php_xml enabled
  • PHP extension php_gd2 enabled (if not compiled in)
  • PHP extension php_zip enabled

The PHP extensions should be already enabled, with a standard PHP installation(I didn’t have to enable any extension when I was installing it for the first time).

To install the library we will use Composer:

If you don’t have composer installed on your current machine, here is a how to install it.

After the process was finished, you can test if it’s working correctly using this simple code:

This should generate a new spreadsheet that looks like this:

Leave a Comment