Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to access array offset on value of type int { DefaultValueBinder.php line 82 }

I have an export to excel button which downloads excel file. However when i click it shows me error as Trying to access array offset on value of type int

My code is this:

public static function dataTypeForValue($pValue = null)
    {
        // Match the value against a few data types
        if ($pValue === null) {
            return PHPExcel_Cell_DataType::TYPE_NULL;
        } elseif ($pValue === '') {
            return PHPExcel_Cell_DataType::TYPE_STRING;
        } elseif ($pValue instanceof PHPExcel_RichText) {
            return PHPExcel_Cell_DataType::TYPE_INLINE;
  } elseif ($pValue[0] === '=' && strlen($pValue) > 1) {   //error comes in this line
            return PHPExcel_Cell_DataType::TYPE_FORMULA;
        } elseif (is_bool($pValue)) {
            return PHPExcel_Cell_DataType::TYPE_BOOL;
        } elseif (is_float($pValue) || is_int($pValue)) {
            return PHPExcel_Cell_DataType::TYPE_NUMERIC;
        } elseif (preg_match('/^[\+\-]?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $pValue)) {
            $tValue = ltrim($pValue, '+-');
            if (is_string($pValue) && $tValue[0] === '0' && strlen($tValue) > 1 && $tValue[1] !== '.') {
                return PHPExcel_Cell_DataType::TYPE_STRING;
            } elseif ((strpos($pValue, '.') === false) && ($pValue > PHP_INT_MAX)) {
                return PHPExcel_Cell_DataType::TYPE_STRING;
            }
            return PHPExcel_Cell_DataType::TYPE_NUMERIC;
        } elseif (is_string($pValue) && array_key_exists($pValue, PHPExcel_Cell_DataType::getErrorCodes())) {
            return PHPExcel_Cell_DataType::TYPE_ERROR;
        }

        return PHPExcel_Cell_DataType::TYPE_STRING;
    }
}

what can be the solution for this..?

like image 953
Deb Avatar asked Jun 24 '20 11:06

Deb


3 Answers

In the PHPExcel file "DefaultValueBinder.php", replace this line 82:

} elseif ($pValue[0] === '=' && strlen($pValue) > 1) {

with the following:

} elseif (0 === strpos($pValue, '=') && strlen($pValue) > 1) {
like image 54
Vivek Raskar Avatar answered Oct 26 '22 12:10

Vivek Raskar


(!is_int($pValue) && $pValue[0] === '=' && strlen($pValue) > 1) should work. $pValue[0] will not work with integers so check if it is an int or not before continuing.

like image 40
Edvinas Platovas Avatar answered Oct 26 '22 13:10

Edvinas Platovas


I update some files in library and It's work fine for me at php 7.4 Please check updated code library :

Google Drive LInk

like image 28
Govinda Yadav Avatar answered Oct 26 '22 13:10

Govinda Yadav