Question

Im trying to implement Converting single sheet in an XLS file to CSV with PHPExcel - Memory exhausted but got stuck in the PHP Excel loading process.

I downloaded the pack (http://phpexcel.codeplex.com/) and, following the install instructions, copied the folder 'Classes' to three directories:

1) C:\xampp\htdocs\mycode - just my current working directory

2) C:\xampp\php\pear - bcs its what i get when I echo get_include_path();

and

3) C:\xampp\php\pear\PEAR - you know, just in case...

still when I run:

include 'PHPExcel.php';
include 'PHPExcel/IOFactory.php';

I get the following error messages:

Warning: include(PHPExcel.php): failed to open stream: No such file or directory in C:\xampp\htdocs\mycode\paths.php on line 5

Warning: include(): Failed opening 'PHPExcel.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\mycode\paths.php on line 5

Warning: include(PHPExcel/IOFactory.php): failed to open stream: No such file or directory in C:\xampp\htdocs\mycode\paths.php on line 6

Warning: include(): Failed opening 'PHPExcel/IOFactory.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\mycode\paths.php on line 6

tks in advance...

Était-ce utile?

La solution

...copied the folder 'Classes' to three directories

Seems the hint is right there. Shouldn't it be

require_once 'Classes/PHPExcel.php';

Alternatively, add the Classes folder to your include path...

set_include_path(implode(PATH_SEPARATOR, [
    realpath(__DIR__ . '/Classes'), // assuming Classes is in the same directory as this script
    get_include_path()
]));

require_once 'PHPExcel.php';

Autres conseils

In my case i juste had to replace my

include "../classes/Projects.php";

by this:

require_once "./classes/Projects.php";

Generally when you are including files it is going to be relative to the file you are calling the include from. Make sure you are looking in the correct directory. I say this because the way you include files seems as if the PHPExcel files should be in the exact same directory, but it looks like you put this into a folder called classes.

For example, if your directory structure looks like this:

C:\
   - xampp\
       - htdocs\
           - mycode\
               - classes\  (where you extracted your files to...)
                   - (more files and subdirectories in here)
               - index.php (where you are including file into...)

Then you are including from where index.php is located. So if PHPExcel is located in the classes folder, then your include statement should look like this:

include classes/PHPExcel.php or include classes/PHPExcel/IOFactory.php

this module worked for me initially. but then I added Yii2 and spent a long time looking for a solution to the problem. for those who find this topic, as I did and also added Yii2 to Yii1, I will leave this solution.

for me first helped this.

        spl_autoload_unregister(['YiiBase', 'autoload']);
        require_once Yii::app()->params['rootPath'] . '/PHPExcel/Classes/PHPExcel.php';
        spl_autoload_register(['YiiBase', 'autoload']);

when i added Yii2 i changed

        spl_autoload_unregister(['Yii', 'autoload']);
        spl_autoload_unregister(['YiiBase', 'autoload']);
        require_once Yii::app()->params['rootPath'] . '/PHPExcel/Classes/PHPExcel.php';
        spl_autoload_register(['YiiBase', 'autoload']);
        spl_autoload_register(['Yii', 'autoload']);

next use

  $objPHPExcel = new \PHPExcel();
  ...
  $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top