I am using Php Excel,I am creating export button to my page. Is there a way to export the excel file without saving it to my server?.I tried it but the exported excel is corrupted.
<?php
require_once dirname(__FILE__) . '/phpexcel/Classes/PHPExcel.php';
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
$objPHPExcel = new PHPExcel();
$result = mysql_query("select * from employee");
$headings = array("ID","employeeid","employeefirstname","employelastname");
$headingrow = 1;
$colheader = 'A';
foreach ($headings as $heading) {
$objPHPExcel->getActiveSheet()->setCellValue($colheader.$headingrow, $heading);
$colheader++;
}
$row = 2;
while($row_data = mysql_fetch_assoc($result)) {
$col = 0;
foreach($row_data as $key=>$value) {
$objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $value);
$col++;
}
$row++;
}
$objPHPExcel->getActiveSheet()->setTitle('test');
$objPHPExcel->setActiveSheetIndex(0);
$filename = 'test.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Transfer-Encoding: binary');
$objWriter->save('php://output');
exit;
?>