Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @param $file
- * @return mixed
- */
- public static function excelToArray($file)
- {
- $json['status'] = 'error';
- $fileExtension = pathinfo($file['name']);
- $fileExtension = $fileExtension['extension'];
- if ($fileExtension == 'xls' || $fileExtension == 'xlsx') {
- $data = array();
- $PHPExcelReader = \PHPExcel_IOFactory::createReaderForFile($file['tmp_name']);
- $objPHPExcel = $PHPExcelReader->load($file['tmp_name']);
- $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
- array_shift($sheetData);
- foreach ($sheetData as $cell) {
- $data[] = $cell['B'];
- }
- $json['status'] = 'success';
- $json['data'] = $data;
- }
- return $json;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement