download.blade.php 1.02 KB
<?php

  include_once(app_path().'/lib/phpexcel/PHPExcel.php');
  
  $inputFileType = "Excel5";
  $objReader = PHPExcel_IOFactory::createReader($inputFileType);
  $objPHPExcel = $objReader->load("assets/extras/blank.xls");
  $baseRow = 2;

  $tcol=0;$extrahdrarr=array();
  
  $highestColumn = sizeof($fieldsarr);
  for ($head = 0; $head < $highestColumn; $head++){
    $colstr=PHPExcel_Cell::stringFromColumnIndex($head);
    $objPHPExcel->getActiveSheet()->setCellValue($colstr."1", $fieldsarr[$head]);
  }

  $ii=1;
  foreach($alist as $aline)
  {
    $row = $baseRow++; $col = 0;

    foreach ($fieldsarr as $key) {
            $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col++,$row)->setValueExplicit(trim($aline->$key));
          }

  }

  header('Content-Type: application/vnd.ms-excel');
  header('Content-Disposition: attachment;filename="Output.xls"');
  header('Cache-Control: max-age=0');

  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, $inputFileType);
  $objWriter->save('php://output');
  
  return ;

?>