Reading an XLS file with codeigniter 2.0

送分小仙女□ 提交于 2019-12-23 04:54:20

问题


I've got the following problem.

I am trying to read an excel 97 - 2003 (XLS) file. The file is located within the codeigniter folder. Currently i am using the spreadsheet_excel_reader.php library to read the XLS file.

Unfortunately i cannot get it working, it does recognize the XLS file and also reads the file, but when it's done parsing the file, it returns NULL

This is what my method looks like.

$CI =& get_instance();

$this->data_file = "./xls/BolFeed.xls"; //The XLS file and folder

//$CI->spreadsheet_excel_reader->setOutputEncoding('CP1251'); //I've added this one into the library itself.

$CI->spreadsheet_excel_reader->read($this->data_file); //Start reading the XLS file

$this->data_array = $this->spreadsheet_excel_reader->sheets[0]; //This should return my XLS but only returns NULL

var_dump($this->data_array);
die;

I think the method does not cause the problem, but the XLS parse library does.

I hope you guys can help me out, because i've been struggling with this problem for days.

I am using PHP 5.3.0 and CI 2.0.0

Thanks for your efforts.


回答1:


shouldn't $this->spreadsheet_excel_reader->sheets be $CI->spreadsheet_excel_reader->sheets as you are calling $CI->spreadsheet_excel_reader->read in the line above




回答2:


if you do count($this->spreadsheet_excel_reader->sheets) before or after var_dump does it show that the array isn't empty?

And from the docs, it seems like you need to do more that sheets to see data:

$this->spreadsheet_excel_reader->dump($row_numbers=false,$col_letters=false,$sheet=0,$table_class='excel');


来源:https://stackoverflow.com/questions/5898001/reading-an-xls-file-with-codeigniter-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!