2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__ . '/Header.php';
|
|
|
|
|
|
|
|
// Change these values to select the PDF Rendering library that you wish to use
|
|
|
|
// and its directory location on your server
|
2016-08-31 17:18:12 +00:00
|
|
|
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_TCPDF;
|
|
|
|
//$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_MPDF;
|
|
|
|
$rendererName = \PhpOffice\PhpSpreadsheet\Settings::PDF_RENDERER_DOMPDF;
|
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');
|
|
|
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
2016-08-31 16:15:54 +00:00
|
|
|
$spreadsheet = $reader->load(__DIR__ . '/templates/26template.xlsx');
|
|
|
|
|
|
|
|
/* at this point, we could do some manipulations with the template, but we skip this step */
|
2016-10-06 11:49:41 +00:00
|
|
|
$helper->write($spreadsheet, __FILE__, ['Xlsx' => 'xlsx', 'Xls' => 'xls', 'HTML' => 'html']);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Export to PDF (.pdf)
|
|
|
|
$helper->log('Write to PDF format');
|
2017-01-21 15:44:33 +00:00
|
|
|
\PhpOffice\PhpSpreadsheet\Settings::setPdfRendererName($rendererName);
|
2017-01-21 15:58:48 +00:00
|
|
|
$helper->write($spreadsheet, __FILE__, ['Pdf' => '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');
|
2016-08-31 17:18:12 +00:00
|
|
|
$writer = \PhpOffice\PhpSpreadsheet\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);
|