Last active
June 14, 2020 20:07
-
-
Save gridphp/70e96ee4f0225e2a6af2f76b672b2abf to your computer and use it in GitHub Desktop.
PHPExcel sample excel output of array ($arr) - https://www.gridphp.com
This file contains 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
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