PHP Powered XML Excel Spreadsheet Exporter — Donat Studios
source link: https://donatstudios.com/XML_Excel_Exporter
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
XML Excel Exporter
Update 2017: The functionality of "XML Excel Exporter" is now part of the Quorum Exporter project.
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: ).
Limitations:
- File Format is not supported by:
- Open Office
- Google Documents
- Microsoft Office Live
MySQL Example
require('includes/classes/XSpreadsheet.php'); $spread = new XSpreadsheet($fname) $spread->AddWorksheet('Products', mysql_query("Select * From products")) ->AddWorksheet('Categories', mysql_query("Select * From categories")) ->Generate()->Send();
Array Example
require('includes/classes/XSpreadsheet.php'); $data = array( array( 'Column 1', 'Column 2', 'Column 3' ), array( 1, 2, 3 ), ); $spread = new XSpreadsheet($fname) $spread->AddWorksheet('Awesome Sheet', $data ) ->Generate()->Send();
Comment by: Craig R Morton on Jan. 7, 2013
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: http://stackoverflow.com/questions/14162411/preventing-ms-excel-from-stripping-leading-zeros-with-php-5-3/
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 Jan. 7, 2013
XSpreadsheet will prevent zero's from being trimmed
<?php
include('XSpreadsheet.php');
$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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK