Export spreadsheet data in ODS/CSV format with PHP5
The second LGPL library this week is a PHP5 class to export spreadsheet data in different formats. Currently supported are CSV (Comma Separated Values) and ODS (OpenDocument Spreadsheet). While CSV exports are quite ordinary, ODS functionality is something special for your project.
Library’s objectives
We want to provide a library which allows exporting spreadsheet data in a much more comfortable and easier way than it was before. In advanced products we always need different data exports – sometimes also in different formats. While CSV export functionality isn’t challenging for most web developers, ODS export isn’t very common in web products. SpreadsheetExport allows you to export either as CSV or ODS using the same code.
Example
This example shows a simple export of two columns (string and float values).
-
$export = new SpreadsheetExport();
-
$export->filename = "sampleExport"; // extension will be added automatically
-
// Add 3 columns
-
$export->AddColumn("date", 5);
-
$export->AddColumn("string");
-
$export->AddColumn("float");
-
// Now we add 3 rows
-
// Start download as CSV …
-
$export->DownloadCSV();
-
// … or as ODS
-
$export->DownloadODS();
Requirements
Because files in OpenDocument format are simple Zip files holding one or more XML files you need to have installed the ziplib and appropriate PHP extension on your webserver.
Licencing
SpreadsheetExport is published under the GNU Lesser General Public Licence.
Download
You can download SpreadsheetExport from Sourceforge.
Tags: CSV, ODS, OpenDocument, PHP