2013-02-06 54 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