2
votes

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...

4
Then, make sure all files are in their proper folders and the paths are correct. I've used that library before and had no problem using it.Funk Forty Niner
@Fred-ii- tks, this is a bit new to me. isn't it just copying the folder 'Classes' in C:\xampp\php\pear? How do I make sure?user2491612
I ran it from a hosted server. I couldn't say for sure for a local machine. See what Phil posted below. Also make sure that the folder(s) names are correctly spelled, letter-case is important. classes is not the same as Classes on some servers (Unix & Windows are 2 different animals altogether)Funk Forty Niner
One often runs into this error, and to quickly troubleshoot it, follow these steps : stackoverflow.com/a/36577021/2873507Vic Seedoubleyew

4 Answers

5
votes

...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';
1
votes

In my case i juste had to replace my

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

by this:

require_once "./classes/Projects.php";
0
votes

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

0
votes

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');