Created
February 9, 2017 13:13
-
-
Save fbentele/1b756ec5340fc94647731020dcb138a9 to your computer and use it in GitHub Desktop.
export array to xls
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
// 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