需要帮助来解决PHPExcel的excel工作表问题。我正在尝试从数据库生成PHPExcel。问题是excel工作表被创建,内存也被占用,但是内容没有显示,因此它显示空白的excel工作表。
任何帮助表示赞赏。
我的PHPExcel代码,
include './external_libraries/PHPExcel.php';
$arrmixEmpDetails = $this->_mObjExportExcelModel->fetchEmployeeDetails( $this->_mObjDB );
$strFileNameToDownload = 'employee_details_' . date( 'Y-m-d' ) . '.xlsx';
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$intRowCount = 1;
if( count( $arrmixEmpDetails ) > 1 ) {
foreach( $arrmixEmpDetails as $arrmixEmpDetail ) {
$objPHPExcel->getActiveSheet()
->setCellValue( 'A' . $intRowCount, $arrmixEmpDetail['id'] )
->setCellValue( 'B'. $intRowCount, $arrmixEmpDetail['first_name'] )
->setCellValue( 'C'. $intRowCount, $arrmixEmpDetail['last_name'] )
->setCellValue( 'D'. $intRowCount, $arrmixEmpDetail['salary'] )
->setCellValue( 'E'. $intRowCount, $arrmixEmpDetail['department_name'] )
->setCellValue( 'F'. $intRowCount, $arrmixEmpDetail['hire_date'] );
$intRowCount++;
// $intColumnCount = 0;
}
}
// header( 'Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header( 'Content-Disposition: attachment; filename=' . $strFileNameToDownload );
header( 'Cache-Control: max-age=0' );
$objWriter = PHPExcel_IOFactory::createWriter( $objPHPExcel, 'Excel2007' );
ob_get_clean();
$objWriter->save( 'php://output' );