Skip to content

Instantly share code, notes, and snippets.

@fbentele
Created February 9, 2017 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbentele/1b756ec5340fc94647731020dcb138a9 to your computer and use it in GitHub Desktop.
Save fbentele/1b756ec5340fc94647731020dcb138a9 to your computer and use it in GitHub Desktop.
export array to xls
// library needed
// https://github.com/PHPOffice/PHPExcel/
require_once dirname(__FILE__) . '/PHPExcel/Classes/PHPExcel.php';
function make_xls($array){
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("creator")->setTitle("Export");
// Write array to sheet
$objPHPExcel->getActiveSheet()->fromArray($array, NULL, 'A1');
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Anmeldungen');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="export.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 01 Jan 1990 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment