public static function getSheetNameIndex($filePath, $sheetName) { $reader = Process_excel::createExcelReader($filePath); $infos = $reader->listWorksheetInfo($filePath); for ($i = 0; $i < count($infos); $i++) { if ($infos[$i]['worksheetName'] == $sheetName) { return $i; } } }
function estimateLoadingProgress($dataSource_filePath) { $ext = pathinfo($dataSource_filePath, PATHINFO_EXTENSION); $sampleFilePath = $ext == 'xlsx' ? "loadingTimeSample.xlsx" : "loadingTimeSample.xls"; $PHPExcelReader = Process_excel::createExcelReader($dataSource_filePath); $PHPExcelReader->setReadDataOnly(true); $PHPExcelReader->setReadFilter(new NothingFilter()); $sampleStart = time(); $PHPExcelReader->load($sampleFilePath); $sampleEnd = time(); $sampleLoadTime = $sampleEnd - $sampleStart; $sampleLoadTime = $sampleLoadTime > 0.015 ? $sampleLoadTime : 0.015; $targetFileSize = (double) filesize($dataSource_filePath); $sampleFileSize = (double) filesize($sampleFilePath); $estimatedSeconds = $sampleLoadTime * $targetFileSize / $sampleFileSize; $estimatedSeconds = $ext == 'xlsx' ? $estimatedSeconds * 4 : $estimatedSeconds; // Loading time does not increase in linear pattern when the file is small. // So the loading time is timed with an arbitrary number. echo $estimatedSeconds * 10; }