Phpspreadsheet: Fatal error while using Writer\xlsx

Created on 20 Aug 2017  路  16Comments  路  Source: PHPOffice/PhpSpreadsheet

Hi I have an error, help me please... What is the problem please ?

What is the expected behavior?

I want to create a XLSX file

Code ?

<?php
require 'phptoexcel/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');

$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');

What is the current behavior?

There is fatal error :
( ! )聽Fatal error: Class 'PhpOffice\PhpSpreadsheet\Writer\Xlsx' not found in C:\wamp64\www\timax\test.php on line聽12

Which versions of PhpSpreadsheet and PHP are affected?

Last version with PHP 7

question

All 16 comments

@to175
Because you havn't import Xlsx class yet, suggest you move use statement to the top, and you should add a statement "use PhpOffice\PhpSpreadsheet\Writer\Xlsx;" so that you can use the Xlsx writer.

Besides, you can also import IOFactory to make a xlsx waiter.

Sorry, I have modified, this is the right code, i have already Xlsx thats why i dont understand the issue...
Thanks for replying tho :)
What can i do now ? is IOFactory necessary ?

Not really need at all, just a suggest, because use factory pattern may be a little better.

Best wishes.

Even if I have use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
I stille have the error

Have you download the phpSpreadsheet? Have you execute "composer install" command? Are 'phptoexcel' is the correct folder of phpSpreadsheet?

I don't like using commands so I used this https://php-download.com/package/phpoffice/phpspreadsheet

Is it solved?

It is not, with the package I have not to use composer, so I have put the files in my directory and launched a php page, it should have worked but it didnt cf the fatal error

Just now I download "https://php-download.com/package/phpoffice/phpspreadsheet" and use it for your code, there's no error occurred.

The test.php is in the same level folder with phptoexcel, and phptoexcel include all the files I download.

Thanks :) Maybe I do it wrong somewhere... I have put the content of zip in phptoexcel directory and thats all...

Can you show your dir tree?

for example it is C:\wamp64\www\timax\phptoexcel\src\PhpSpreadsheet\Writer
And I have the test.php in timax

I am closing this, because it is not a bug within PhpSpreadsheet but a support question about usage. But feel free to keep the discussion going...

By the way, php-download.com is not recommended, because it includes dev dependencies that you should not need (making the package much bigger that what it should be). Future updates will be harder and managing conflicts between several libraries in your project won't be possible. I strongly encourage you to start using composer instead.

same happened with me using dev-develop. use Version 1.0.0-beta instead.

You are either using composer incorrectly, or not at all. If you are not familiar with it, you should read about it over there: https://getcomposer.org/doc/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

huichen2017 picture huichen2017  路  4Comments

PowerKiKi picture PowerKiKi  路  5Comments

jcroucher picture jcroucher  路  4Comments

PowerKiKi picture PowerKiKi  路  5Comments

noxidsoft picture noxidsoft  路  3Comments