Skip to content

Instantly share code, notes, and snippets.

@pqr
Last active December 12, 2019 07:36
Show Gist options
  • Save pqr/ad12493947e7b1e2910f to your computer and use it in GitHub Desktop.
Save pqr/ad12493947e7b1e2910f to your computer and use it in GitHub Desktop.
optimized example for http://habrahabr.ru/post/269051/
<?php
require 'vendor/autoload.php';
$callStartTime = microtime(true);
$objPHPExcel = PHPExcel_IOFactory::load('multipage.xls');
$sheetsIterator = $objPHPExcel->getWorksheetIterator();
$tmpFileName = microtime(true);
while( $sheetsIterator->valid()) {
// Create new object to write converted data and separate documents sheets
$csvPagePhpExcel = new PHPExcel();
$sheet = $sheetsIterator->current();
$csvPagePhpExcel->addSheet($sheet, 0);
// Creating CSV writer Object and save data to file
$objWriter = PHPExcel_IOFactory::createWriter($csvPagePhpExcel, 'CSV');
$currentTmpFileName = "{$tmpFileName}_sheet_{$sheetsIterator->key()}.csv";
$objWriter->save($currentTmpFileName);
$sheetsIterator->next();
}
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
echo "\n" . $callTime . "\n";
@ionstudio
Copy link

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment