【问题标题】:phpexcel File does not existphpexcel文件不存在
【发布时间】: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例子成功了吗?
  • 是的,如果您需要帮助可以与我联系。

标签: symfony phpexcel


【解决方案1】:

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

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

【讨论】:

  • 你的例子中的 $this 是什么?
  • $this 引用了控制器。此代码行位于控制器中的方法中。
猜你喜欢
  • 1970-01-01
  • 2022-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-27
相关资源
最近更新 更多