0

to get cell from xls

$filename = "upload/" . $nfile;
$type = PHPExcel_IOFactory::identify($filename);
$objReader = PHPExcel_IOFactory::createReader($type);
$objPHPExcel = $objReader->load($filename);
$array = ($objPHPExcel->getSheetNames());
$finarr = [];

It's works.

To get value of cell from Excel by PHPExcel:

foreach($sheetNames as $singleSheetName => $value){
    $vz = ($objPHPExcel->getSheet($singleSheetName)->getCell('L40')->getCalculatedValue());
    return $firarr[$vz];
}

It's works.

I want to optimize code. create a function

function getCorrectCell($a, $b) {
     return ($objPHPExcel->getSheet($a)->getCell($b)->getCalculatedValue());
};

I call getCorrectCell($singleSheetName, 'L40');

error

Got error

PHP message: PHP Notice: Undefined variable: objPHPExcel in /var/www/******/html/secondworker.php on line 13
PHP message: PHP Fatal error: Call to a member function getSheet() on null

How to correctly declarate function and put arguments? Thanks for help!

barbsan
  • 3,418
  • 11
  • 21
  • 28
Andrey Fugas
  • 61
  • 1
  • 8
  • `$objPHPExcel` is undefined. – ArtisticPhoenix Jan 16 '19 at 03:10
  • 2
    Possible duplicate of [Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?](https://stackoverflow.com/questions/16959576/reference-what-is-variable-scope-which-variables-are-accessible-from-where-and) – Nick Jan 16 '19 at 03:24

0 Answers0