Space Cat, Prince Among Thieves

XML Excel Exporter

Update 2017: The functionality of "XML Excel Exporter" is now part of the Quorum Exporter project.

Recent Activity

XSpreadsheet dies after outputting the spreadsheet now, preventing corruption

Repository Restructured
-Working Corpus now in Source Folder
-`Scripts` folder added, includes database dump batch, and HTML viewer
-`Local` folder added, for testing use with local database connections, etc

-Finally! Created an initial
-TODO moved from includes folder into root

This simple class allows you via PHP to export an XML Spreadsheet compatible with all versions of Excel 2003 and up.

The files generated will work with versions of Office 2003 and up. It is considered production safe, and is currently in use in a fair number of production sites.

Unlike CSV or HTML Table exports, you can have multiple worksheets of data! A sheets data can be added to the spreadsheet either by a MySQL query resource or as a 2 dimensional array.

Known bugs:

  • Office 2007/2010 bark about XLS file extensions despite refusing to open XML file extensions downloaded from the internet. (Anyone know a solution?)
  • DOMDocument incorrectly converts/removes non-printable/low range characters (eg: 


  • File Format is not supported by:
    • Open Office
    • Google Documents
    • Microsoft Office Live

MySQL Example

$spread = new XSpreadsheet($fname)
$spread->AddWorksheet('Products', mysql_query("Select * From products"))
    ->AddWorksheet('Categories', mysql_query("Select * From categories"))

Array Example

$data = array(
    array( 'Column 1', 'Column 2', 'Column 3' ),
    array( 1, 2, 3 ),

$spread = new XSpreadsheet($fname)
$spread->AddWorksheet('Awesome Sheet', $data )

Comment by: Craig R Morton on

Craig R Morton's Gravatar Many thanks for making your XSpreadsheet project available on GitHub.

I have downloaded it for the purpose of (hopefully) resolving an issue with leading zeros being stripped automatically by excel.

I have a question on StackOverflow, which probably describes the problem better:

After using your sample code, with a small amendment (to change 1 to 001), I note that the zeros are still being stripped. Is there a workaround for XSpreadsheet?

Comment by: Jesse G. Donat on

Jesse G. Donat's Gravatar

XSpreadsheet will prevent zero's from being trimmed

$data = array( array( 'Column 1', 'Column 2', 'Column 3' ), array( '001', '002', '003' ), );
$spread = new XSpreadsheet('test2.xml.xls');
$spread->AddWorksheet('Awesome Sheet', $data )->Generate()->Send();

displays as follows in this screen shot.

Email address will never be publicly visible.

Basic HTML allowed.