26_Utf8.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\IOFactory;
  3. require __DIR__ . '/../Header.php';
  4. // Read from Xlsx (.xlsx) template
  5. $helper->log('Load Xlsx template file');
  6. $reader = IOFactory::createReader('Xlsx');
  7. $spreadsheet = $reader->load(__DIR__ . '/../templates/26template.xlsx');
  8. // at this point, we could do some manipulations with the template, but we skip this step
  9. $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);
  10. // Export to PDF (.pdf)
  11. $helper->log('Write to PDF format');
  12. IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class);
  13. $helper->write($spreadsheet, __FILE__, ['Pdf']);
  14. // Remove first two rows with field headers before exporting to CSV
  15. $helper->log('Removing first two heading rows for CSV export');
  16. $worksheet = $spreadsheet->getActiveSheet();
  17. $worksheet->removeRow(1, 2);
  18. // Export to CSV (.csv)
  19. $helper->log('Write to CSV format');
  20. /** @var \PhpOffice\PhpSpreadsheet\Writer\Csv $writer */
  21. $writer = IOFactory::createWriter($spreadsheet, 'Csv');
  22. $filename = $helper->getFilename(__FILE__, 'csv');
  23. $callStartTime = microtime(true);
  24. $writer->save($filename);
  25. $helper->logWrite($writer, $filename, $callStartTime);
  26. // Export to CSV with BOM (.csv)
  27. $filename = str_replace('.csv', '-bom.csv', $filename);
  28. $helper->log('Write to CSV format (with BOM)');
  29. $writer->setUseBOM(true);
  30. $callStartTime = microtime(true);
  31. $writer->save($filename);
  32. $helper->logWrite($writer, $filename, $callStartTime);