Export MySQL Data to Excel using PHPSpreadsheet in CodeIngiter

Описание к видео Export MySQL Data to Excel using PHPSpreadsheet in CodeIngiter

In this video, you will be able to export mysql data to excel using phpspreadsheet.

Steps:
I have created one button with text download format, I will changing that to an anchor tag.
Pass the href of your controller function.

In controller ,
firstly include vendor/autoload.php file
after that use
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

Spreadsheet - for creating a worksheet in excel
xlsx -for creating excel file

we will be passing worksheet (spreadsheet) to xlsx - this will create a excel file that contain a worksheet.
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet-getActiveSheet();
$sheet- setCellValue('A1', 'Hello World !');

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

For download of excel file, you have to add headers
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="hello_world.xlsx"');

save will save that in a particular folder
For download you need to pass php://output to download in excel
$writer- save("php://output");

Documentation:
https://phpspreadsheet.readthedocs.io...

Starting hello world:
https://phpspreadsheet.readthedocs.io...

Code Link:
https://github.com/sushma-singh-yadav...

Playlist:
   • PHPSpreadsheet in CodeIgniter  
#codeigniter #knowledgethrusters

Комментарии

Информация по комментариям в разработке