Useful Tip:
You can use this online HTML entity encoder/decoder to generate your code examples.
Excel Export is simply a class that works under the PHPExcel library, for convenience and save time when developing.
Download Library Export DemoUnzip <PHPExcel>
Just include the file <DataExcel.php>
• The length of cols and rows they must be the same
<?php
include 'DataExcel.php';
// in case of long data
ini_set("memory_limit", -1);
/*config the file
To change the download directory, add 'dirName' => 'yourDir' to config
It is advisable to change it if you are on local servers.
default dir name = 'var/www/html/LibraryFolderName'
That can change dependig of your server.
*/
DataExcel::config(array(
'conbinatedCells' => 'A1:G1', // conbination cells is required
'fileName' => 'Customers', // defaultfileName => excelExport
'sheetTitle' => 'Customers Report' //defaultsheetTitle => excelExport
));
/** set global styles
*The global styles are adapted to the full sheet, if you want to change you must call the method again.
*styles available:
*alignVertical
*backgroundColor
*border =>array('color' => '')
*color
*fontFamily
*fontSize
*fontWeight
*height
*textAlign
*width
*/
DataExcel::styles(array(
'height' => 17,
'fontSize' => 12.50,
"fontFamily" => "Roboto",
));
// You can also pass the style parameters in this way and it will not affect the other styles
DataExcel::setTitle(['text' => 'Customers List', 'height' => 25, 'fontSize' => 25.12, 'textAlign' => 'center']);
// set the cols
DataExcel::setCols(['text' => 'Cod'])
::setCols(['text' => 'Name'])
::setCols(['text' => 'Id-Card'])
::setCols(['text' => 'Phone'])
::setCols(['text' => 'Invoiced'])
::setCols(['text' => 'Paid'])
::setCols(['text' => 'Balance']);
// set background to all rows
DataExcel::styles(array('backgroundColor' => 'cc8888'));
// set the rows data
DataExcel::setRows(array(
['text' => '0001'],
['text' => 'Juan Perez'],
['text' => '565-988-325'],
['text' => '(829) 123-4567'],
['text' => '$5,000.00'],
['text' => '$1,000.00'],
['text' => '$4,000.00']
));
// This over write the previous background for all rows
DataExcel::styles(array('backgroundColor' => 'ffffff'));
// set the rows data
DataExcel::setRows(array(
['text' => '0002'],
['text' => 'Pedro Enrrique'],
['text' => '254-976-851'],
['text' => '(829) 987-6543'],
['text' => '$1,850.00'],
['text' => '$1,850.00'],
['text' => '$0.00']
));
// process the data
DataExcel::process();
// for download the file
DataExcel::download();
You can use this online HTML entity encoder/decoder to generate your code examples.