2013-02-06 55 views
0

我想用PHPExcel读取xlsx文件。我的文件在我的本地和我的代码显示我这个错误。 *phpexcel文件不存在

无法打开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()方法查找文件的目录?我迷路了 在此先感谢

+1

检查权限,尝试用完整路径前缀文件名 –

+0

您是否成功加载phpexcel示例? – periback2

+0

是的,如果你需要一些帮助,你可以联系我。 – Freenando

回答

0

解决:我认为它没有加载该目录(mybundle /控制器)的权限。我已将xlsx文件移至web/upload目录,并且此功能正常工作。

$objPHPExcel = $this->get('xls.load_xls2007')->load($this->get('kernel')->getRootDir() .'/../web/upload/MunicipioPreinscripcion.xlsx'); 
+0

你的例子中的$是什么? –

+0

$这是参考控制器。该代码行是在一个控制器中的方法。 – Freenando