首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使PHPExcel和CodeIgniter集成工作

无法使PHPExcel和CodeIgniter集成工作
EN

Stack Overflow用户
提问于 2014-03-08 18:58:23
回答 1查看 2.3K关注 0票数 0

这让我困惑了好几天,我无法让下面的代码起作用:

代码语言:javascript
复制
public function index (){
    //load our new PHPExcel library
    $this->load->library('excel');
    $objPHPExcel = new PHPExcel();
    //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');

    }


}

我得到的只是一个空白页。我试图跟踪代码,以确定为什么它不能工作,而行$this->load->library('excel');导致了它。

我在excel.php中创建了/libraries文件,粘贴了web上示例中的代码。

有人能帮我一下这个吗?

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2014-04-04 17:26:57

问题在于如何使用PHPExcel安装CodeIgniter。

回头见:PHPExcel error in CodeIgniter "Unable to load the requested class: iofactory"

将phpexcel文件夹放入应用程序/第三方并创建一个库。(对于图书馆,请使用他的答案中由“devrooms”推荐的类)

然后在控制器中执行以下操作:

代码语言:javascript
复制
$this->load->library("excel");
$this->excel->load("/path/to/input.xls");
$this->excel->setActiveSheetIndex(0);
$this->excel->getActiveSheet()->SetCellValue('B2', "whatever");
$this->excel->save("/path/to/output.xls");

如果上面的内容不起作用,请参阅此的答案,以禁用您服务器上的php安全模式

phpexel and codeigniter getting error

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22273666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档