Advertisement
koki2000

phpspreadsheet

Nov 15th, 2021
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.70 KB | None | 0 0
  1.     public function getexcel($file)
  2.     {
  3.         $reader = IOFactory::createReader('Xlsx');
  4.         $reader->setReadDataOnly(TRUE);
  5.         $spreadsheet = $reader->load($file);
  6.         $worksheet = $spreadsheet->getActiveSheet();
  7.         $highestRow = $worksheet->getHighestRow();
  8.         $highestColumn = $worksheet->getHighestColumn();
  9.         $highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
  10.  
  11.         for ($row = 1; $row <= $highestRow; ++$row)
  12.         {
  13.             $exceldata[($row-1)] = array();
  14.             for ($col = 1; $col <= $highestColumnIndex; ++$col)
  15.             {
  16.                 $value = $worksheet->getCellByColumnAndRow($col, $row)->getValue();
  17.                 $exceldata[($row-1)][] = $value;
  18.                
  19.             }
  20.         }
  21.         return $exceldata;
  22.     }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement