Created
December 14, 2010 10:14
-
-
Save khepin/740233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyExcel { | |
private static $format = ''; | |
public static function setFormat(sfEvent $event) { | |
self::$format = $event['format']; | |
} | |
public static function setContent(sfEvent $event, $response) { | |
if (self::$format == 'xlsx') { | |
// Include PHPExcel and its autoloader | |
include(sfConfig::get('sf_lib_dir').'/vendor/phpexcel/Classes/PHPExcel.php'); | |
// write response to an xml file (in prod, use unique filenames should be used) | |
$temporary_file_name = sfConfig::get('sf_cache_dir').'/excel.xml'; | |
file_put_contents($temporary_file_name, $response); | |
// load the file | |
$excel_reader = new PHPExcel_Reader_Excel2003XML(); | |
$excel_sheet = $excel_reader->load($temporary_file_name); | |
// output the file | |
$excel_writer = new PHPExcel_Writer_Excel2007($excel_sheet); | |
$excel_writer->save('php://output'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment