PHP code example of pear / spreadsheet_excel_writer
1. Go to this page and download the library: Download pear/spreadsheet_excel_writer library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pear / spreadsheet_excel_writer example snippets
use Spreadsheet_Excel_Writer;
$filePath = __DIR__ . '/output/out.xls';
$xls = new Spreadsheet_Excel_Writer($filePath);
// 8 = BIFF8
$xls->setVersion(8);
$sheet = $xls->addWorksheet('info');
// only available with BIFF8
$sheet->setInputEncoding('UTF-8');
$headers = [
'id',
'name',
'email',
'code',
'address'
];
$row = $col = 0;
foreach ($headers as $header) {
$sheet->write($row, $col, $header);
$col++;
}
for ($id = 1; $id < 100; $id++) {
$data = [
'id' => $id,
'name' => 'Name Surname',
'email' => '[email protected] ',
'password' => 'cfcd208495d565ef66e7dff9f98764da',
'address' => '00000 North Tantau Avenue. Cupertino, CA 12345. (000) 1234567'
];
$sheet->writeRow($id, 0, $data);
}
$xls->close();
$xls = new Spreadsheet_Excel_Writer();
$titleFormat = $xls->addFormat();
$titleFormat->setFontFamily('Helvetica');
$titleFormat->setBold();
$titleFormat->setSize(10);
$titleFormat->setColor('orange');
$titleFormat->setBorder(1);
$titleFormat->setBottom(2);
$titleFormat->setBottomColor(44);
$titleFormat->setAlign('center');
$sheet = $xls->addWorksheet('info');
$sheet->write(0, 0, 'Text 123', $titleFormat);
$xls = new Spreadsheet_Excel_Writer();
$xls->send('excel_'.date("Y-m-d__H:i:s").'.xls');