To use the pure PHP to create or edit an Excel spreadsheet, we will use PHPExcel library that can read and write a lot of spreadsheet formats including xls, xlsx, ods and csv. Before we continue, carefully check the version PHP 5.2 or later and the following PHP extensions installed on your server: php_zip, php_xml and php_gd2.
Create a spreadsheet
Create a spreadsheet with PHP is one example of an application of the most common, used to export data to an Excel spreadsheet. Check the following code, learn how to use PHPExcel create a sample Excel spreadsheet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
If you want to download a spreadsheet instead of saving it to the server, do the following:
1 2 3 4 |
|
Edit an existing spreadsheet
Edit a spreadsheet and create a spreadsheet similar in PHP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Ready to print a spreadsheet
To prepare for printing a spreadsheet, we will set the paper orientation, size and margins:
1 2 3 4 5 6 |
|
PHPExcel used together with Laravel
PHPExcel library can also be used Laravel framework. Review the following PHP package (here) and install it through Composer. After installation is complete, you can use the following code to export data from a database into an Excel spreadsheet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|