Download the PHP package rafaelmaza/spout without Composer

On this page you can find all versions of the php package rafaelmaza/spout. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package spout

Spout

Latest Stable Version Project Status Build Status Scrutinizer Code Quality Code Coverage Total Downloads

Spout is a PHP library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way. Contrary to other file readers or writers, it is capable of processing very large files while keeping the memory usage really low (less than 3MB).

Join the community and come discuss about Spout: Gitter

Installation

Composer (recommended)

Spout can be installed directly from Composer.

Run the following command:

Manual installation

If you can't use Composer, no worries! You can still install Spout manually.

Before starting, make sure your system meets the requirements.

  1. Download the source code from the Releases page
  2. Extract the downloaded content into your project.
  3. Add this code to the top controller (index.php) or wherever it may be more appropriate:

Requirements

Basic usage

Reader

Regardless of the file type, the interface to read a file is always the same:

If there are multiple sheets in the file, the reader will read all of them sequentially.

Writer

As with the reader, there is one common interface to write data to a file:

For XLSX and ODS files, the number of rows per sheet is limited to 1,048,576. By default, once this limit is reached, the writer will automatically create a new sheet and continue writing data into it.

Advanced usage

If you are looking for how to perform some common, more advanced tasks with Spout, please take a look at the Wiki. It contains code snippets, ready to be used.

Configuring the CSV reader and writer

It is possible to configure both the CSV reader and writer to specify the field separator as well as the field enclosure:

Additionally, if you need to read non UTF-8 files, you can specify the encoding of your file this way:

By default, the writer generates CSV files encoded in UTF-8, with a BOM. It is however possible to not include the BOM:

Configuring the XLSX and ODS readers and writers

Row styling

It is possible to apply some formatting options to a row. Spout supports fonts, background, borders as well as alignment styles.

Adding borders to a row requires a object.

Spout will use a default style for all created rows. This style can be overridden this way:

Unfortunately, Spout does not support all the possible formatting options yet. But you can find the most important ones:

Category Property API
Font Bold StyleBuilder::setFontBold()
Italic StyleBuilder::setFontItalic()
Underline StyleBuilder::setFontUnderline()
Strikethrough StyleBuilder::setFontStrikethrough()
Font name StyleBuilder::setFontName('Arial')
Font size StyleBuilder::setFontSize(14)
Font color StyleBuilder::setFontColor(Color::BLUE)
StyleBuilder::setFontColor(Color::rgb(0, 128, 255))
Alignment Wrap text StyleBuilder::setShouldWrapText(true|false)

New sheet creation

It is also possible to change the behavior of the writer when the maximum number of rows (1,048,576) have been written in the current sheet:

Using custom temporary folder

Processing XLSX and ODS files require temporary files to be created. By default, Spout will use the system default temporary folder (as returned by sys_get_temp_dir()). It is possible to override this by explicitly setting it on the reader or writer:

Strings storage (XLSX writer)

XLSX files support different ways to store the string values:

In order to keep the memory usage really low, Spout does not optimize strings when using shared strings. It is nevertheless possible to use this mode.

Note on Apple Numbers and iOS support

Apple's products (Numbers and the iOS previewer) don't support inline strings and display empty cells instead. Therefore, if these platforms need to be supported, make sure to use shared strings!

Date/Time formatting

When reading a spreadsheet containing dates or times, Spout returns the values by default as DateTime objects. It is possible to change this behavior and have a formatted date returned instead (e.g. "2016-11-29 1:22 AM"). The format of the date corresponds to what is specified in the spreadsheet.

Playing with sheets

When creating a XLSX or ODS file, it is possible to control which sheet the data will be written into. At any time, you can retrieve or set the current sheet:

It is also possible to retrieve all the sheets currently created:

If you rely on the sheet's name in your application, you can access it and customize it this way:

Please note that Excel has some restrictions on the sheet's name:

  • it must not be blank
  • it must not exceed 31 characters
  • it must not contain these characters: \ / ? * : [ or ]
  • it must not start or end with a single quote
  • it must be unique

Handling these restrictions is the developer's responsibility. Spout does not try to automatically change the sheet's name, as one may rely on this name to be exactly what was passed in.

Fluent interface

Because fluent interfaces are great, you can use them with Spout:

Running tests

On the master branch, only unit and functional tests are included. The performance tests require very large files and have been excluded. If you just want to check that everything is working as expected, executing the tests of the master branch is enough.

If you want to run performance tests, you will need to checkout the perf-tests branch. Multiple test suites can then be run, depending on the expected output:

For information, the performance tests take about 30 minutes to run (processing 1 million rows files is not a quick thing).

Performance tests status: Build Status

Frequently Asked Questions

How can Spout handle such large data sets and still use less than 3MB of memory?

When writing data, Spout is streaming the data to files, one or few lines at a time. That means that it only keeps in memory the few rows that it needs to write. Once written, the memory is freed.

Same goes with reading. Only one row at a time is stored in memory. A special technique is used to handle shared strings in XLSX, storing them - if needed - into several small temporary files that allows fast access.

How long does it take to generate a file with X rows?

Here are a few numbers regarding the performance of Spout:

Type Action 2,000 rows (6,000 cells) 200,000 rows (600,000 cells) 2,000,000 rows (6,000,000 cells)
CSV Read < 1 second 4 seconds 2-3 minutes
Write < 1 second 2 seconds 2-3 minutes
XLSX Read
inline strings
< 1 second 35-40 seconds 18-20 minutes
Read
shared strings
1 second 1-2 minutes 35-40 minutes
Write 1 second 20-25 seconds 8-10 minutes
ODS Read 1 second 1-2 minutes 5-6 minutes
Write < 1 second 35-40 seconds 5-6 minutes

Does Spout support charts or formulas?

No. This is a compromise to keep memory usage low. Charts and formulas requires data to be kept in memory in order to be used. So the larger the file would be, the more memory would be consumed, preventing your code to scale well.

Support

Need to contact us directly? Email [email protected] and be sure to include the name of this project in the subject.

You can also ask questions, submit new features ideas or discuss about Spout in the chat room:
Gitter

Copyright and License

Copyright 2015 Box, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


All versions of spout with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
ext-zip Version *
ext-xmlreader Version *
ext-simplexml Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rafaelmaza/spout contains the following files

Loading the files please wait ....