2 u012550878 u012550878 于 2013.10.25 22:14 提问

phpexcel 导入 excel出现问题,求解答!!!

使用phpexcel导入excel出现问题,怎么解决???
exception 'PHPExcel_Reader_Exception' with message 'Could not open 20131025085845.xls for reading! File does not exist, or it is not readable.' in E:\wamp\www\student_message\ThinkPHP\Extend\Vendor\Excel\PHPExcel\Shared\OLERead.php:80 Stack trace: #0 E:\wamp\www\student_message\ThinkPHP\Extend\Vendor\Excel\PHPExcel\Reader\Excel5.php(1067): PHPExcel_Shared_OLERead->read('20131025085845....') #1 E:\wamp\www\student_message\ThinkPHP\Extend\Vendor\Excel\PHPExcel\Reader\Excel5.php(571):

执行代码如下:
public function read($filename,$encode,$file_type){

if(strtolower ( $file_type )=='xls')//判断excel表类型为2003还是2007

{

Vendor("Excel.PHPExcel.Reader.Excel5");

$objReader = PHPExcel_IOFactory::createReader('Excel5');

}elseif(strtolower ( $file_type )=='xlsx')

{

Vendor("Excel.PHPExcel.Reader.Excel2007");

$objReader = PHPExcel_IOFactory::createReader('Excel2007');

}

$objReader->setReadDataOnly(true);

$objPHPExcel = $objReader->load($filename);

$objWorksheet = $objPHPExcel->getActiveSheet();

$highestRow = $objWorksheet->getHighestRow();

$highestColumn = $objWorksheet->getHighestColumn();

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

$excelData = array();

for ($row = 1; $row <= $highestRow; $row++) {

for ($col = 0; $col < $highestColumnIndex; $col++) {

$excelData[$row][] =(string)$objWorksheet->getCellByColumnAndRow($col, $row)->getValue();

}

}

return $excelData;

}

2个回答

hys136371825
hys136371825   2016.04.30 19:08

楼主我也遇到了同样的问题,百度了一下我得出的靠谱结论是: 'Could not open 20131025085845.xls for reading! File does not exist, or it is not readable.说明excel文件不存在或者不可读,原因很可能是文件夹有权限,我用的xampp,我看了下我tmp文件夹(存放临时文件的)的属性,果然是只读,不仅如此,所有的文件夹及其文件都是只读。但是修改属性没用啊,修改完后右击还是只读,我也很郁闷..

qq_32723451
qq_32723451 请问怎么改的,有印象吗?
4 个月之前 回复
mozhi2008
mozhi2008   2017.06.20 12:02

文件名不能用中文,只能用英文!!!!!!

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!