PHPSpreadsheet

Spout

 
 

PHP Library for CSV XLSX & ODS Spreadsheets

Open Source PHP API to Create, Read, Convert & Manipulate CSV, XLSX or ODS Spreadsheets.

 

Spout is an open source PHP library that enables software developers to read and write CSV, XLSX as well as ODS spreadsheets files. It is fast and scalable as compare to other file readers or writers. It is capable of handling small as well as very large spreadsheets files while keeping the memory usage really low. It only requires 3MB of memory for processing any spreadsheet file.

Spout API is very developer-friendly. It provides a simple and integrated API for reading as well as creating different types of spreadsheets like CSV, XLSX, and ODS. It is also very easy to switch from one type of spreadsheet to other types.

Getting Started with Spout API

First of all, you need to have the PHP version 7.1 or higher installed on your system. You can directly install Spout from Composer. Run the following command:

Command for Composer

$ composer require box/spout

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

You can also install Spout manually, first, you need to download the source code from the GitHub and extract the downloaded content into your project. After that, you need to add this code to the top controller or any other appropriate place.

PHP Library to Read & Write CSV, XLSX & ODS Spreadsheet

Spout API enables software developers to create spreadsheet files in 3 popular file formats. It supports working with CSV, XLSX and ODS file formats. Please note that Spout guesses the reader type based on the file extension. If the extension is not standard (.csv, .ods, .xlsx - lower/uppercase), a specific reader can be created directly.

Add Data to Existing Spreadsheet via PHP API

Spout API gives the developer the capability to update an existing spreadsheet by adding data to it. It’s a very common practice to add new data to an existing spreadsheet. For example, a teacher wants to add a record of a new student by adding a new row containing information of the last students. Spout API does not keep full spreadsheet representation in memory. Thus avoid memory issues while working with large spreadsheets. To modify a spreadsheet it creates a new one similar to the existing one and adds required data to the new spreadsheet.  Now simply remove the old file and rename the new one. The newly created file now contains the new data.

Reading Data from a Specific Sheet

Spout API enables PHP developers to access and read data from a specific sheet inside a spreadsheet.  Usually, a spreadsheet contains several worksheets. If a user is interested to read data from only one sheet and skip the other sheets. The users just need to know the name and position of the spreadsheet.