2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2017-05-17 22:02:17 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
|
2017-10-01 08:48:59 +00:00
|
|
|
require __DIR__ . '/../Header.php';
|
2016-08-31 16:15:54 +00:00
|
|
|
|
2016-10-06 11:39:10 +00:00
|
|
|
// Read from Xlsx (.xlsx) template
|
|
|
|
$helper->log('Load Xlsx template file');
|
2017-05-17 22:02:17 +00:00
|
|
|
$reader = IOFactory::createReader('Xlsx');
|
2017-10-01 08:48:59 +00:00
|
|
|
$spreadsheet = $reader->load(__DIR__ . '/../templates/26template.xlsx');
|
2016-08-31 16:15:54 +00:00
|
|
|
|
2017-10-01 11:07:04 +00:00
|
|
|
// at this point, we could do some manipulations with the template, but we skip this step
|
2017-01-22 08:39:23 +00:00
|
|
|
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Export to PDF (.pdf)
|
|
|
|
$helper->log('Write to PDF format');
|
2017-10-21 16:54:14 +00:00
|
|
|
IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class);
|
2017-01-22 08:39:23 +00:00
|
|
|
$helper->write($spreadsheet, __FILE__, ['Pdf']);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Remove first two rows with field headers before exporting to CSV
|
|
|
|
$helper->log('Removing first two heading rows for CSV export');
|
|
|
|
$worksheet = $spreadsheet->getActiveSheet();
|
|
|
|
$worksheet->removeRow(1, 2);
|
|
|
|
|
|
|
|
// Export to CSV (.csv)
|
|
|
|
$helper->log('Write to CSV format');
|
2019-07-01 18:59:34 +00:00
|
|
|
/** @var \PhpOffice\PhpSpreadsheet\Writer\Csv $writer */
|
2017-05-17 22:02:17 +00:00
|
|
|
$writer = IOFactory::createWriter($spreadsheet, 'Csv');
|
2016-08-31 16:15:54 +00:00
|
|
|
$filename = $helper->getFilename(__FILE__, 'csv');
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$writer->save($filename);
|
|
|
|
$helper->logWrite($writer, $filename, $callStartTime);
|
|
|
|
|
|
|
|
// Export to CSV with BOM (.csv)
|
|
|
|
$filename = str_replace('.csv', '-bom.csv', $filename);
|
|
|
|
$helper->log('Write to CSV format (with BOM)');
|
|
|
|
$writer->setUseBOM(true);
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$writer->save($filename);
|
|
|
|
$helper->logWrite($writer, $filename, $callStartTime);
|