PHP Demo Application - Source Code
/Framework/Model/Libraries/OutputFormats/Excel.php
<?php
/**
* Script Contents: Apeel_Framework_Model_Libraries_Export_OutputFormats_Excel Class
* Extends Apeel_Framework_Model_Libraries_Export_OutputFormats_Abstract
* @package Apeel_Framework_Model_Libraries
*/
/**
* Generates a document in Microsoft Excel (R) format.
*
* Writes the data in csv (comma seperated values) format with a .csv extension
* which is interpreted as a spreadsheet by Excel (if installed).
*
* If you need more advanced Excel formatting features, please install
* the PHPExcel Library which creates native excel format documents.
* http://phpexcel.codeplex.com/
*
* @package Apeel_Framework_Model_Libraries
* @version 1.1.0
* @author John W. King (email: contact@apeelframework.net)
* @copyright City Business Logic Limited 2001-2011
* @license Dual MIT / GNU Lesser General Public License Version 3
*/
class Apeel_Framework_Model_Libraries_Export_OutputFormats_Excel extends Apeel_Framework_Model_Libraries_Export_OutputFormats_Abstract
{
/**
* Sets header to Excel format (application/vnd.ms-excel) and outputs the
* supplied data (which must be in CSV format) using the filename given,
* which should not include the .csv extension as this will be added
* automatically.
*
* @param string $data
* @param string $filename
* @return void
*/
public function generateDocument($data, $filename) {
if ($filename == '') {
$filename = md5(rand()) . '.csv';
}
header('Content-Type: application/vnd.ms-excel');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Disposition: Attachment; Filename=' . $filename);
echo $data;
}
}
?>