OpenDocument Spreadsheet Three years ago I was pleased to announce SpreadsheetExport 0.1.0 by Fusonic - an open-source PHP library provided by Fusonic. Its purpose was to enable PHP developers to export spreadsheet-like data to various file formats while only writing their export logic once.

You need to implement some kind of spreadsheet export in nearly every application - so did we in our Social Intranet Solution. Problem was that there are open standards like CSV, ODS, TSV etc. but depending on the spreadsheet application you're using you will prefer either ODS/CSV for OpenOffice or TSV/XLS for Microsoft Excel. Our spreadsheet export library solves this problem. You write the export logic once and in the end you decide which file format should be sent to the client.

The new version - 0.2 - makes use of new PHP 5.3 features like namespaces, SPL classes etc. The example below illustrates how easy it is to create a CSV file with SpreadsheetExport:


// Instantiate new spreadsheet
$export = new Spreadsheet();

// Add columns
$export->AddColumn(new DateColumn("Date"));
$export->AddColumn(new TextColumn("Comment"));
$export->AddColumn(new NumericColumn("Population"));

// Add data rows
$export->AddRow(array("1987-01-01", "world population reached 5 billion", 5));
$export->AddRow(array("1999-01-01", "world population reached 6 billion", 6));
$export->AddRow(array("2012-01-01", "world population reaches 7 billion", 7));

// Instantiate writer (CSV)
$writer = new CsvWriter();
$writer->charset = CsvWriter::CHARSET_ISO;

// Instantiate writer (TSV)
$writer = new TsvWriter();
$writer->charset = TsvWriter::CHARSET_ISO;

// Instantiate writer (ODS)
$writer = new OdsWriter();

// Save
// $export->Save($writer, "/tmp/Sample");

// Download
$export->Download($writer, "Sample");

Currently the project includes three export writers for CSV, TSV and ODS file format either your users or you can choose from.

License & Availibility

The new 0.2 SpreadsheetExport is licensed under the MIT license and is available on GitHub!

Feel free to use and deploy SpreadsheetExport, create pull request or fork the entire project :-)


comments powered by Disqus