0

我正在尝试使用 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() 方法正在查找文件的目录?我迷路了 提前谢谢

4

1 回答 1

0

已解决:我认为它没有加载此目录(mybundle/controller)中的权限。我已将 xlsx 文件移动到 web/upload 目录,这可以正常工作。

$objPHPExcel = $this->get('xls.load_xls2007')->load($this->get('kernel')->getRootDir() .'/../web/upload/MunicipioPreinscripcion.xlsx');
于 2013-06-06T07:04:45.197 回答