Skip to content

Instantly share code, notes, and snippets.

@khepin
Created December 14, 2010 10:14
Show Gist options
  • Save khepin/740233 to your computer and use it in GitHub Desktop.
Save khepin/740233 to your computer and use it in GitHub Desktop.
<?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