/ *
- excel table export
- @ param string $fileName file name
- @ param array $headArr header name
- @ param array $data data to be exported
- @ author static7 * /
function excelExport ($fileName ="", $headArr = [], $data = []) {
$fileName .= "_" . date("Y_m_d", Request::instance()->time()) . ".xls";
$objPHPExcel = new \PHPExcel();
$objPHPExcel->getProperties();
$key = ord("A"); //
foreach ($headArr as $v) {
$colum = chr($key);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . "1", $v);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . "1", $v);
$key += 1;
}
$column = 2;
$objActSheet = $objPHPExcel->getActiveSheet();
foreach ($data as $key => $rows) { //
$span = ord("A");
foreach ($rows as $keyName => $value) { //
$objActSheet->setCellValue(chr($span) . $column, $value);
$spanPP;
}
$columnPP;
}
$fileName = iconv("utf-8", "gb2312", $fileName); //
$objPHPExcel->setActiveSheetIndex(0); // ,Excel
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment;filename="$fileName"");
header("Cache-Control: max-age=0");
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel5");
$objWriter->save("php://output"); //
exit();
}
/ / this is to tell the browser to download the excel file, so how to generate the excel file to the specified directory without telling the browser to download it locally?