PHPExcel: excel sheet downloading but content not showing

59 Views Asked by At

Need a help to resolve the excel sheet issue with PHPExcel. I'm trying to generate the PHPExcel from database. The problem is that excel sheet get creating and memory also get occupied but the content is not showing so it's showing blank excel sheet.

Any help appreciated.

My PHPExcel code,

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' );
0

There are 0 best solutions below