2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2020-05-24 11:03:07 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Csv as CsvReader;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Csv as CsvWriter;
|
2017-05-17 22:02:17 +00:00
|
|
|
|
2017-10-01 08:48:59 +00:00
|
|
|
require __DIR__ . '/../Header.php';
|
|
|
|
$spreadsheet = require __DIR__ . '/../templates/sampleSpreadsheet.php';
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
$helper->log('Write to CSV format');
|
2019-07-01 18:59:34 +00:00
|
|
|
/** @var \PhpOffice\PhpSpreadsheet\Writer\Csv $writer */
|
2020-05-24 11:03:07 +00:00
|
|
|
$writer = new CsvWriter($spreadsheet);
|
|
|
|
$writer->setDelimiter(',')
|
2018-01-28 06:59:38 +00:00
|
|
|
->setEnclosure('"')
|
|
|
|
->setSheetIndex(0);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$filename = $helper->getTemporaryFilename('csv');
|
|
|
|
$writer->save($filename);
|
|
|
|
$helper->logWrite($writer, $filename, $callStartTime);
|
|
|
|
|
|
|
|
$helper->log('Read from CSV format');
|
|
|
|
|
2019-07-01 18:59:34 +00:00
|
|
|
/** @var \PhpOffice\PhpSpreadsheet\Reader\Csv $reader */
|
2020-05-24 11:03:07 +00:00
|
|
|
$reader = new CsvReader();
|
|
|
|
$reader->setDelimiter(',')
|
2018-01-28 06:59:38 +00:00
|
|
|
->setEnclosure('"')
|
|
|
|
->setSheetIndex(0);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$spreadsheetFromCSV = $reader->load($filename);
|
2017-01-22 08:39:23 +00:00
|
|
|
$helper->logRead('Csv', $filename, $callStartTime);
|
2020-05-24 11:03:07 +00:00
|
|
|
unlink($filename);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
2016-10-06 11:39:10 +00:00
|
|
|
// Write Xlsx
|
2017-01-22 08:39:23 +00:00
|
|
|
$helper->write($spreadsheetFromCSV, __FILE__, ['Xlsx']);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Write CSV
|
|
|
|
$filenameCSV = $helper->getFilename(__FILE__, 'csv');
|
2019-07-01 18:59:34 +00:00
|
|
|
/** @var \PhpOffice\PhpSpreadsheet\Writer\Csv $writerCSV */
|
2020-05-24 11:03:07 +00:00
|
|
|
$writerCSV = new CsvWriter($spreadsheetFromCSV);
|
2016-08-31 16:15:54 +00:00
|
|
|
$writerCSV->setExcelCompatibility(true);
|
|
|
|
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$writerCSV->save($filenameCSV);
|
|
|
|
$helper->logWrite($writerCSV, $filenameCSV, $callStartTime);
|