我尝试按照以下教程将PHPExcel库实现为Codeigniter http://www.ahowto.net/php/easily-integrateload-phpexcel-into-codeigniter-framework/
出于某种原因,当我运行看起来像这样的测试时
reports.php控制器 localhost / fticketarchive / index.php?/ reports / excelTest
<?php
class Reports extends CI_Controller
{
function excelTest(){
//load our new PHPExcel library
$this->load->library('Excel');
//activate worksheet number 1
$this->excel->setActiveSheetIndex(0);
//name the worksheet
$this->excel->getActiveSheet()->setTitle('test worksheet');
//set cell A1 content with some text
$this->excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
//change the font size
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
//make the font become bold
$this->excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
//merge cell A1 until D1
$this->excel->getActiveSheet()->mergeCells('A1:D1');
//set aligment to center for that merged cell (A1 to D1)
$this->excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$filename='just_some_random_name.xls'; //save our workbook as this file name
header('Content-Type: application/vnd.ms-excel'); //mime type
header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
header('Cache-Control: max-age=0'); //no cache
//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
//if you want to save it as .XLSX Excel 2007 format
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
//force user to download the Excel file without writing it to server's HD
$objWriter->save('php://output');
}
}
所以出于某种原因我在localhost / fticketarchive / index.php?/ reports / excelTest
我在控制台中收到以下错误,没有服务器响应。 500内部服务器错误
任何想法都将不胜感激!谢谢。
答案 0 :(得分:0)
您是否尝试将对图书馆的调用移至__construct?
class Reports extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('excel');
}
function exceltest(){
//proceed
}
}
至少对我来说,这很有效。