PhpSpreadSheet Javascript AJAX jQuery PHP Example MORE

PhpSpreadsheet Example

Installation :

Use composer to install PhpSpreadsheet into your project:

composer require phpoffice/phpspreadsheet

Or also download the exe file from the link.

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

Hello World Example
This would be the simplest way to write a spreadsheet:

Example-1

<?php
require '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');
    

Change the color of multiple cell

Example-2

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

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

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$spreadsheet->getActiveSheet()->getStyle('A1:G1')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('00FF7F');
$spreadsheet->getActiveSheet()->getStyle('A1:G1')
->getFont()->getColor()->setARGB(\PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED);
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');