Advertisement
alpa_s

Untitled

Jun 29th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. /**
  2. * @param $file
  3. * @return mixed
  4. */
  5. public static function excelToArray($file)
  6. {
  7. $json['status'] = 'error';
  8. $fileExtension = pathinfo($file['name']);
  9. $fileExtension = $fileExtension['extension'];
  10. if ($fileExtension == 'xls' || $fileExtension == 'xlsx') {
  11. $data = array();
  12.  
  13. $PHPExcelReader = \PHPExcel_IOFactory::createReaderForFile($file['tmp_name']);
  14. $objPHPExcel = $PHPExcelReader->load($file['tmp_name']);
  15.  
  16. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  17. array_shift($sheetData);
  18. foreach ($sheetData as $cell) {
  19. $data[] = $cell['B'];
  20. }
  21. $json['status'] = 'success';
  22. $json['data'] = $data;
  23. }
  24. return $json;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement