我正在尝试使用 PHPExcel 1.7.8 + CodeIgniter 2.1.3 导出 XLS 文件
但我收到此错误:
无法加载请求的类:
iofactory
这是我的控制器代码:
//expoxt to excel all admin data
function export_excel_admin()
{
//$data['resultsadmin'] = $this->admin_model->get_all_data_admin();
//var_dump($data['resultsadmin']);
//$this->load->view('administrator/export_excel/export_excel_admin', $data);
$query = $this->db->get('tbl_admin');
if(!$query)
return false;
// Starting the PHPExcel library
$this->load->library('excel');
$this->load->library('PHPexcel/IOFactory');
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
$objPHPExcel->setActiveSheetIndex(0);
// Field names in the first row
$fields = $query->list_fields();
$col = 0;
foreach ($fields as $field)
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
$col++;
}
// Fetching the table data
$row = 2;
foreach($query->result() as $data)
{
$col = 0;
foreach ($fields as $field)
{
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $data->$field);
$col++;
}
$row++;
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
// Sending headers to force the user to download the file
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Products_'.date('dMy').'.xls"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');
}
啊,我也删除了 IOFactory.php 文件中的“PHPExcel_”部分,这个问题有什么解决方案吗?