2016-08-31 16:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require __DIR__ . '/Header.php';
|
|
|
|
$spreadsheet = require __DIR__ . '/templates/sampleSpreadsheet.php';
|
|
|
|
|
|
|
|
$helper->log('Write to CSV format');
|
2016-08-31 17:18:12 +00:00
|
|
|
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'CSV')->setDelimiter(',')
|
2016-08-31 16:15:54 +00:00
|
|
|
->setEnclosure('"')
|
|
|
|
->setSheetIndex(0);
|
|
|
|
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$filename = $helper->getTemporaryFilename('csv');
|
|
|
|
$writer->save($filename);
|
|
|
|
$helper->logWrite($writer, $filename, $callStartTime);
|
|
|
|
|
|
|
|
$helper->log('Read from CSV format');
|
|
|
|
|
2016-08-31 17:18:12 +00:00
|
|
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('CSV')->setDelimiter(',')
|
2016-08-31 16:15:54 +00:00
|
|
|
->setEnclosure('"')
|
|
|
|
->setSheetIndex(0);
|
|
|
|
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$spreadsheetFromCSV = $reader->load($filename);
|
|
|
|
$helper->logRead('CSV', $filename, $callStartTime);
|
|
|
|
|
2016-10-06 11:39:10 +00:00
|
|
|
// Write Xlsx
|
|
|
|
$helper->write($spreadsheetFromCSV, __FILE__, ['Xlsx' => 'xlsx']);
|
2016-08-31 16:15:54 +00:00
|
|
|
|
|
|
|
// Write CSV
|
|
|
|
$filenameCSV = $helper->getFilename(__FILE__, 'csv');
|
2016-08-31 17:18:12 +00:00
|
|
|
$writerCSV = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheetFromCSV, 'CSV');
|
2016-08-31 16:15:54 +00:00
|
|
|
$writerCSV->setExcelCompatibility(true);
|
|
|
|
|
|
|
|
$callStartTime = microtime(true);
|
|
|
|
$writerCSV->save($filenameCSV);
|
|
|
|
$helper->logWrite($writerCSV, $filenameCSV, $callStartTime);
|