public static function exportExcel($fileName,$displayFields,$exportList)
{
$objExcel = new PHPExcel();
//set document Property
$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
$objActSheet = $objExcel->getActiveSheet();
$key = ord("A");
foreach ($displayFields as $filedValue)
{
$colum = chr($key);
$objActSheet->setCellValue($colum.'1', $filedValue);
$key += 1;
}
$column = 2;
foreach($exportList as $key => $rows){
$span = ord("A");
foreach($rows as $keyName=>$value){
$j = chr($span);
$objActSheet->setCellValue($j.$column, $value);
$span++;
}
$column++;
}
//*************************************
$outfile = $fileName.".xls";
//export to exploer
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$outfile.'"');
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$objWriter->save('php://output');
exit;
}
这是我编程的时候一个小实例,在这里mark下, 如果你也想做一个简单的实例的话,可以直接拿来用,主要是对行,列的读取。