Advertisement
Guest User

Untitled

a guest
Mar 16th, 2015
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2. function excelToArray($file, $highestColumn) {
  3.     include 'Classes/PHPExcel/IOFactory.php';
  4.  
  5.     $inputFileName = $file;
  6.  
  7.     //  Read your Excel workbook
  8.     try {
  9.         $inputFileType = call_user_func(array('PHPExcel_IOFactory', 'identify'), $inputFileName);
  10.         $objReader = call_user_func(array('PHPExcel_IOFactory','createReader'),$inputFileType);
  11.         //$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
  12.         //$objReader = PHPExcel_IOFactory::createReader($inputFileType);
  13.         $objPHPExcel = $objReader->load($inputFileName);
  14.     } catch(Exception $e) {
  15.         die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
  16.     }
  17.  
  18.     $sheet = $objPHPExcel->getSheet(0);
  19.     $highestRow = $sheet->getHighestRow();
  20.     //$highestColumn = 'E';
  21.  
  22.     //  Loop through each row of the worksheet in turn
  23.     for ($row = 1; $row <= $highestRow; $row++){
  24.         //  Read a row of data into an array
  25.         $rowData[] = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
  26.         //  Insert row data array into your database of choice here
  27.     }
  28.     return $rowData;
  29. }
  30.  
  31. $data = excelToArray('test.xlsx','E');
  32. print_r($data);
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement