0
public function genrate_business_XLS_file($export_data) { 
            // create file name
            $fileName = 'Business-report-'.date("d-M-Y").'-'.time().'.xlsx';  
            // load excel library
            $this->load->library('excel');
            $objPHPExcel = new PHPExcel();
            $objPHPExcel->setActiveSheetIndex(0);
            // set Header
            $objPHPExcel->getActiveSheet()->SetCellValue('A1', 'USER ID');
            $objPHPExcel->getActiveSheet()->SetCellValue('B1', 'BUSINESS NAME');
            $objPHPExcel->getActiveSheet()->SetCellValue('C1', 'PHONE');
            $objPHPExcel->getActiveSheet()->SetCellValue('D1', 'EMAIL');   
            // set Row
            $rowCount = 2;
            foreach ($export_data as $val) 
            {

            //echo"<pre>";print_r($val);die;
                $action = '';
                if($val['b_status']==0){
                    $action = 'Rejected Application';
                } else if($val['b_status']==1){
                    $action = 'Approved Application';
                }else if($val['b_status']==2){
                    $action = 'New Application';
                }
                $objPHPExcel->getActiveSheet()->SetCellValue('A' . $rowCount, $val['b_id']);
                $objPHPExcel->getActiveSheet()->SetCellValue('B' . $rowCount, $val['b_name']?$val['b_name']:'N/A');
                $objPHPExcel->getActiveSheet()->SetCellValue('C' . $rowCount, $val['b_phone']?$val['b_phone']:'N/A');
                $objPHPExcel->getActiveSheet()->SetCellValue('D' . $rowCount, $val['b_email']?$val['b_email']:'N/A');
                $rowCount++;
            }

            $objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
            $objWriter->save($fileName);
            // download file
            header("Content-Description: File Transfer");
            header("Content-Type: application/vnd.ms-excel"); 
            redirect(site_url().$fileName);
                
    }`
4

1 回答 1

1

将文件保存到不在服务器上的 php 输出

header("Content-Type: application/vnd.ms-excel"); 
header('Content-Disposition: attachment;filename="'.$fileName.'"');
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('php://output');
于 2021-01-14T07:07:50.333 回答