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);
}`
1条答案
按热度按时间olmpazwi1#
将文件保存到不在服务器上的php输出