Excel Calculation using PHPSpreadsheet in Codeigniter

Excel Calculation using PHPSpreadsheet in Codeigniter

Knowledge Thrusters

3 года назад

2,457 Просмотров

In this video, you will be able to do basic excel calculation using phpspreadsheet in codeigniter.

In this tutorial, while exporting mysql data to excel file , you will be setting formula for the excel column that will be calculated in excel.

In my excel file, I have some products with quantity and price. So, we will be doing calculation of amount of each product and then total of the amount of the products.

For amount calculation for each product
Amount= quantity * price
in phpspreadsheet, we can achieve this using :
$sheet- setCellValue('E8','=C8 * D8');
E8 - column index, you can your you own column
C8,B8 - column and row for which multiplication should be done

For addition or total of product amount
$sheet- setCellValue('E8','=SUM(E2:E5')');
SUM is excel formula which takes parameter for calculation

For download excel file, you can watch this video :
https://youtu.be/gXbVfO5xS9g

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/en/latest/

Starting hello world:
https://phpspreadsheet.readthedocs.io/en/latest/#hello-world

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

Playlist:
https://www.youtube.com/playlist?list=PLfZdD6t4BR8Po8-G2H0e8UFIBpyDpBzHs

#codeigniter #knowledgethrusters #phppsreadsheet

Тэги:

#Overview #of #HTML5 #phpspreadsheet #codeigniter #composer #codeigniter_phpspreadsheet #Installation_of_PhpSpreadsheet_in_CodeIgniter_using_Composer #phpspreadsheet_installation #download_excel_using_phpspreadsheet #download_excel_using_phpspreadsheet_in_codeigniter #download_excel_in_codeigniter #export_mysql_data_to_excel #export_data_to_excel #excel_calculation #excel_calculation_in_codeigniter #excel_calculation_phpspreadsheet #excel
Ссылки и html тэги не поддерживаются


Комментарии:

@target1402
@target1402 - 11.12.2023 13:37

Can we adjust the cell height and width of the colum and rows if so how?

Ответить
@mymecer
@mymecer - 15.09.2022 08:23

Nice work, work do you use =COUNTIF frmula with phpsreadsheet?

Ответить
@amitech2951
@amitech2951 - 18.08.2022 23:39

Please upload a video on “how to highlight duplicate values in column “

Ответить
@nirajkumarsingh8654
@nirajkumarsingh8654 - 18.01.2022 19:03

Great Job, I Appreciate it

Ответить
@ibrahimkhan7867
@ibrahimkhan7867 - 29.05.2021 21:31

Very nice and helpful

Ответить