0

I think I'm missing something guys and I'm a beginner. I'm trying to build a website which includes uploading a 100k lines of excel and processing them and I've tried some libraries but with no luck, the box/spout sounds appealing with all the positive reviews it has so here is my problem. I've installed composer on the same folder my my project, installed spout and got the vendor folder which contains box and spout. the problem is when ever I use the use keyword to test the reader I get a white blank page on my website.

I tried changing the use command to :

use vendor\box\spout\src\Spout\Reader\ReaderFactory;

But with no luck.

Removing the use word give a fatal error obviously. Can you guys point me in the right direction.

Thanks.

chris85
  • 23,255
  • 7
  • 28
  • 45
nasser
  • 9
  • 6

2 Answers2

2

the namespace of ReaderFactory is actually: Box\Spout\Reader\ReaderFactory

you can also use the object directly without "use":

\Box\Spout\Reader\ReaderFactory::create('csv');
Marcin Orlowski
  • 67,279
  • 10
  • 112
  • 132
wodka
  • 1,067
  • 8
  • 17
  • Also worth noting that unless you have an autoloader, you will need to call `require("vendor/box/spout/src/Spout/Reader/ReaderFactory.php");` (or whatever the path/file may be) – Niet the Dark Absol May 05 '16 at 21:09
  • The spout manual states that if composer is used I don't need to 'require' anything. – nasser May 05 '16 at 23:00
  • I tried both these two below but didn't work. I'm getting "Fatal error: Class 'vendor\Box\Spout\Common\ReaderFactory' not found in " $reader = \Box\Spout\Common\ReaderFactory::create('XLSX'); // for XLSX files and $reader = \vendor\box\spout\src\Spout\Common\ReaderFactory::create('XLSX'); // for XLSX files – nasser May 05 '16 at 23:03
  • since you use composer do you include the autoload file of composer? the file should be in vendor/autoload.php – wodka May 06 '16 at 18:17
  • You still need to import the autoload.php file generated by Composer when you installed Spout. You should do it in your top-level controller – Adrien May 16 '16 at 21:01
0

It turned out I misplaced the "namespace" keyword putting it inside the function rather than the very top of the file. it all worked out when I moved it.

nasser
  • 9
  • 6