Documentation

https://phpspreadsheet.readthedocs.io/en/latest/

Using in your PHP file

Add these to the top of your PHP file:

//Include for PhpSpreadsheet:
require_once '/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

Depending on your server you might need something like this instead:

  require_once $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';    //In this example the "vendor/" folder is above the sites "pubic_html/" folder

You can test it works using their example test code:

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

  $writer = new Xlsx($spreadsheet);
  $writer->save('hello world.xlsx');
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *