【发布时间】:2013-02-06 15:31:13
【问题描述】:
我正在尝试使用 PHPExcel 读取 xlsx 文档。我的文档在我的本地,我的代码向我显示了这个错误。 *
无法打开 MunicipioPreinscripcion.xlsx 进行阅读!文件不 存在。
*
这是我的代码(我的 excel 文档是我的控制器的当前目录)
#namespace Backend\AlumnosBundle\Controller
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
$inputFileName = 'MunicipioPreinscripcion.xlsx';
$inputFileNameWithPath = PHPEXCEL_ROOT.$inputFileName;
if(file_exists($inputFileNameWithPath)) {
echo 'exist'; //Allways show exist
echo $inputFileNameWithPath."<br>";
} else {
echo 'dont exist';
}
/** Identify the type of $inputFileName **/
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
/** Create a new Reader of the type that has been identified **/
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
/** Advise the Reader that we only want to load cell data **/
$objReader->setReadDataOnly(true);
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load($inputFileName); //This is where throw the error
我做错了什么? 如何显示 load() 方法正在查找文件的目录?我迷路了 提前致谢
【问题讨论】:
-
检查权限,尝试在文件名前加上完整路径
-
你加载phpexcel例子成功了吗?
-
是的,如果您需要帮助可以与我联系。