2

I am having trouble using the spout library in kohana 3.2 to import a big Excel file into mysql. These are the installation steps I have taken:

In the portal file index.php, I added this line of code:

require_once APPPATH.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.'kohana'.DIRECTORY_SEPARATOR.'Spout'.DIRECTORY_SEPARATOR."Autoloader/autoload.php";

This is my reader method:

public static function reader($filename){

    $result = array();

    $reader = ReaderFactory::create(Type::XLSX);
    $reader->open($filename);


    while ($reader->hasNextRow()) {
        $row = $reader->nextRow();
        $code = $row[1];
        $result[] = $code;
    }

    return $result;
}

When I try calling the method, this error message appears:

ERROR: ErrorException [ 1 ]: Class 'ReaderFactory' not found ~ APPPATH/classes/kohana/spoutexcel.php [ 70 ]
2015-09-25 14:29:10 --- STRACE: ErrorException [ 1 ]: Class 'ReaderFactory' not found ~ APPPATH/classes/kohana/spoutexcel.php [ 70 ]

What am I doing wrong?

Spout can be found here: https://github.com/box/spout

Anders Marzi Tornblad
  • 18,896
  • 9
  • 51
  • 66
hhq163
  • 21
  • 1
  • 3

2 Answers2

1

How did you install Spout? If you used Composer, you'll need to include (require_once) the autoload.php file generated by composer when you installed Spout.

If you did not use Composer, you can follow the instructions here: https://github.com/box/spout#manual-installation. It explains which file you need to include to autoload Spout classes.

And as @mrBrown mentioned, don't forget to define the namespaces, by using use Box\Spout\Reader\ReaderFactory;

Adrien
  • 1,929
  • 1
  • 13
  • 23
0

Did you define the namespace?

use Box\Spout\Reader\ReaderFactory;

mrBrown
  • 153
  • 1
  • 10