Sunday, March 20, 2016

Create an Excel file from PHP

<?php

function toExcel()
{
//Download PZHPExcel from https://phpexcel.codeplex.com/# and make sure you include the PHPExcel.php
include_once "classes/PHPExcel.php" ;
$sheet = new PHPExcel();
$activeSheet= $sheet->getActiveSheet();
$activeSheet->setCellValue("A1","SL#");
$activeSheet->setCellValue("B1","Name");
$activeSheet->setCellValue("C1","Mobile Number");
$activeSheet->setCellValue("D1","Image");

header("Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-disposition: attachment; filename='report.xlsx'");
$xlWriter = PHPExcel_IOFactory::createWriter($sheet, 'Excel2007');
$xlWriter->save('php://output');
exit;
}

//Call the function
toExcel();
?>

No comments:

Post a Comment