PHP

HOW TO CREATE EXCEL SPREADSHEET IN PHP

(quick guide & example)

Open the command line, navigate to your project folder, enter composer require phpoffice/phpspreadsheet.

Composer will automatically download the latest version into the vendor/ folder.

DOWNLOAD PHPSPREADSHEET

01

LOAD PHP SPREADSHEET require "vendor/autoload.php"; use PhpOffice\PhpSpreadsheet\ Spreadsheet; use PhpOffice\PhpSpreadsheet\ Writer\Xlsx;

CREATE EXCEL SPREADSHEET (A)

02

CREATE A NEW SPREADSHEET $spreadsheet = new Spreadsheet();

CREATE EXCEL SPREADSHEET (B)

03

GET WORKSHEET + WRITE TO CELL $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue("A1", "Hello World!");

SAVE FILE $writer = new Xlsx($spreadsheet); $writer->save("demo.xlsx");