Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PHPExcel sample excel output of array ($arr) - https://www.gridphp.com
include_once(dirname(__FILE__).'/excel/PHPExcel/IOFactory.php');
$objPHPExcel = new PHPExcel();
// autosize excel columns
foreach(range('A','Z') as $columnID)
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setAutoSize(true);
$objPHPExcel->getActiveSheet()->fromArray($arr, NULL, 'A1');
// write excel2007 standard xlsx
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$filename = $this->options["export"]["filename"];
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'.xlsx"');
// if ssl and IE, remove above cache-control and add following
if ( (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") || $_SERVER["SERVER_PORT"] == "443" )
{
header('Cache-Control: private');
header('Pragma: token');
}
else
{
header('Cache-Control: max-age=0');
}
$objWriter->save('php://output');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.