1

需要帮助来解决 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' );
4

0 回答 0