PHP Classes

PHP Export Data: Export data in CSV, TSV, or Excel XML formats

Recommend this page to a friend!
  Info   View files Documentation   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 370 All time: 6,811 This week: 488Up
Version License PHP version Categories
php-export-data 1.0.0Custom (specified...5PHP 5, Files and Folders


This class can export data in CSV, TSV, or Excel XML formats.

It can take data in arrays to be added as rows of tabular data.

The class can export the data in several output formats as the data rows are added to the tabular data stream.

The class can be exported to the formats CSV, TSV, or Excel XML (aka SpreadsheeML) either to a file or directly to the browser.

Picture of Ionut-Alexandru Toma
Name: Ionut-Alexandru Toma <contact>
Classes: 1 package by
Country: Romania Romania
Age: 32
All time rank: 363672 in Romania Romania
Week rank: 259 Up5 in Romania Romania Up


php-export-data by Eli Dickinson

Released under the permissive MIT License:

A simple library for exporting tabular data to Excel-friendly XML, CSV, or TSV. It supports streaming exported data to a file or directly to the browser as a download so it is suitable for exporting large datasets (you won't run out of memory).

Excel XML code is based on Excel_XML by Oliver Schwarz (

How to use it


// When executed in a browser, this script will prompt for download 
// of 'test.xls' which can then be opened by Excel or OpenOffice.

require 'php-export-data.class.php';

// 'browser' tells the library to stream the data directly to the browser.
// other options are 'file' or 'string'
// 'test.xls' is the filename that the browser will use when attempting to 
// save the download
$exporter = new ExportDataExcel('browser', 'test.xls');

$exporter->initialize(); // starts streaming data to web browser

// pass addRow() an array and it converts it to Excel XML format and sends 
// it to the browser
$exporter->addRow(array("This", "is", "a", "test")); 
$exporter->addRow(array(1, 2, 3, "123-456-7890"));

// doesn't care how many columns you give it

$exporter->finalize(); // writes the footer, flushes remaining data to browser.

exit(); // all done


See the test/ directory for more examples.

Some other options for creating Excel files from PHP are listed here:

  Files folder image Files  
File Role Description
Files folder imagetest (3 files)
Accessible without login Plain text file LICENSE Lic. License text
Plain text file php-export-data.class.php Class Class source
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file test_big_excel_file.php Example Example script
  Accessible without login Plain text file test_excel_browser.php Example Example script
  Accessible without login Plain text file test_tsv_string.php Example Example script

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:6,811
This week:488Up
User Comments (1)
Interesting and good.
6 years ago (Alekos Psimikakis)