|
楼主 |
发表于 2011-2-24 12:46:46
|
显示全部楼层
闲话咱就不说了,直接来点干的
在这之前要下载点东西, http://phpexcel.codeplex.com/releases/view/26479
下载phpexcel1.7.5 解压出来放在根目录。
在CI控制器中直接写方法
function read_excel(){
set_include_path(get_include_path() . PATH_SEPARATOR . './phpexcel/');
//set_include_path(' http://localhost/PHPExcel/phpexcel/');
/** PHPExcel */
include 'PHPExcel.php';
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
/** include php_excel5 */
include 'PHPExcel/Reader/Excel5.php';
$reader = new PHPExcel_Reader_Excel5();
$reader->setReadDataOnly(true); // Not read styles
$excel = $reader->load("uploads/yyy.xls"); //excel的路径
echo "<pre>";
$data=$excel->getActiveSheet()->toArray();
print_r($data);
}
这样就可以读取出来excel的内容了,经本人测试能够正常使用。这样说的够明白了吧,
论坛里找到这个帖子
但是报错
Fatal error: Uncaught exception 'Exception' with message 'The filename D:\APMServ5.2.6\www\htdocs\zexy\uploads/yyy.xls is not recognised as an OLE file' in D:\APMServ5.2.6\www\htdocs\zexy\phpexcel\PHPExcel\Shared\OLERead.php:87 Stack trace: #0 D:\APMServ5.2.6\www\htdocs\zexy\phpexcel\PHPExcel\Reader\Excel5.php(948): PHPExcel_Shared_OLERead->read('D:\APMServ5.2.6...') #1 D:\APMServ5.2.6\www\htdocs\zexy\phpexcel\PHPExcel\Reader\Excel5.php(506): PHPExcel_Reader_Excel5->_loadOLE('D:\APMServ5.2.6...') #2 D:\APMServ5.2.6\www\htdocs\zexy\system\application\controllers\php_excel.php(20): PHPExcel_Reader_Excel5->load('D:\APMServ5.2.6...') #3 [internal function]: Php_excel->read_excel() #4 D:\APMServ5.2.6\www\htdocs\zexy\system\codeigniter\CodeIgniter.php(236): call_user_func_array(Array, Array) #5 D:\APMServ5.2.6\www\htdocs\zexy\index.php(117): require_once('D:\APMServ5.2.6...') #6 {main} thrown in D:\APMServ5.2.6\www\htdocs\zexy\phpexcel\PHPExcel\Shared\OLERead.php on line 87 |
|