Import EXCEL happens exception at PHP7.4,
Exception->message() is:
Trying to access array offset on value of type int.
Expected behavior:
import a xlsx file as i running the code on php72w
Actual behavior:
happened after I uploaded my server circumstance from php7.2 to php7.4 when I import a Excel would be fail like above.
would be normal again if I downgrade from php7.4 to php7.2.
$extension=$request->file()['file']->getClientOriginalExtension();
$extension[0] = strtoupper($extension[0]);
Excel::import(new RejectedImport(), $request->file()['file']->path(),null,$extension);
And what is in Import Class:
<?php
namespace App\Imports;
use App\Commodity;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class CommodityImport implements ToCollection, WithHeadingRow
{
protected $isOverride=false;
public function __construct($isOverride)
{
if($isOverride=='1')
$this->isOverride=true;
}
/**
* @param Collection $collections
*/
public function collection(Collection $collections)
{
foreach ($collections as $row)
{
$barcode = $row['barcode'] ?? $row['BARCODE'] ?? $row['Barcode'];
if(!$barcode)continue;
$name = $row['name'] ?? $row['NAME'] ?? $row['Name'] ?? '';
$sku = $row['sku'] ?? $row['SKU'] ?? $row['Sku'] ?? '';
$owner = $row['owner'] ?? $row['owner_name'] ?? $row['OWNER'] ?? $row['Owner'] ?? '';
$commodity=Commodity::where('barcode',$row['barcode'])->first();
if($commodity){
if($this->isOverride){
$name?$commodity['name']= $name:false;
$sku?$commodity['sku']= $sku:false;
$owner?$commodity['owner_name']= $owner:false;
$commodity->update();
}
}else{
Commodity::create([
'name' => $name,
'sku' => $sku,
'owner_name' => $owner,
'barcode' => $barcode,
]);
}
}
}
}
Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/3.1/getting-started/contributing.html) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.
Can you show a bit more stacktrace, I cannot confirm the bug when using the package on PHP7.4. Maybe it's something in your own code?
Hi @patrickbrouwers thanks for the package, I'm a big fan of it!
I am getting a similar error after upgrading, although it is during an export, and the stacktrace indicates the problem is with phpsreadsheet, not Laravel-Excel, but google brought me here.
Here is the stacktrace:
#0 /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php(56): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()
#1 /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/DefaultValueBinder.php(34): PhpOffice\\PhpSpreadsheet\\Cell\\DefaultValueBinder::dataTypeForValue()
#2 /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Cell.php(184): PhpOffice\\PhpSpreadsheet\\Cell\\DefaultValueBinder->bindValue()
#3 /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Worksheet/Worksheet.php(2510): PhpOffice\\PhpSpreadsheet\\Cell\\Cell->setValue()
#4 /vendor/maatwebsite/excel/src/Sheet.php(402): PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet->fromArray()
#5 /vendor/maatwebsite/excel/src/Sheet.php(502): Maatwebsite\\Excel\\Sheet->append()
#6 /vendor/maatwebsite/excel/src/Sheet.php(368): Maatwebsite\\Excel\\Sheet->appendRows()
#7 /vendor/maatwebsite/excel/src/Sheet.php(195): Maatwebsite\\Excel\\Sheet->fromCollection()
#8 /vendor/maatwebsite/excel/src/Writer.php(73): Maatwebsite\\Excel\\Sheet->export()
#9 /vendor/maatwebsite/excel/src/Excel.php(176): Maatwebsite\\Excel\\Writer->export()
#10 /vendor/maatwebsite/excel/src/Excel.php(97): Maatwebsite\\Excel\\Excel->export()
#11 /app/Console/Commands/EmailCardRequestList.php(89): Maatwebsite\\Excel\\Excel->store()
Fixed in PhpSpreadsheet, see https://github.com/PHPOffice/PhpSpreadsheet/issues/1300
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) {
This will fix the "Trying to access array offset on value of type int" error. But you will also need to conduct a find and replace for curly braces throughout the PHPExcel code to address the "Array and string offset access syntax with curly braces is deprecated" error which also affects PHP ugrades to 7.4. I simply replaced them with "[" and "]" everywhere and everything is working fine again.
DefaultValueBinder.php inside of vendor folder? or where is it? same problem here.
DefaultValueBinder.php inside of vendor folder? or where is it? same problem here.
My apologies. I should have been more specific. In my installation, it is located in the PHPExcel folder at this location: PHPExcel\Cell\DefaultValueBinder.php
It may vary from your installation. But you should be able to run a search for it on your system.
the line i think is the 62, not 82 my friend! and i hope that it will work 'cause im stress out. I cant find the solution to error in my project : Error ERROR: Trying to access array offset on value of type int '/Cell/DefaultValueBinder.php:56'. I have high hopes!
This is the path : third_party/PHPExcel/Classes/PHPExcel/Cell/DefaultValueBinder.php
Here third_party means where you have kept your PHPExcel folder
Now search === '=' and check if there is matching line then replace with that particular to
0 === strpos($pValue, '=')
Rest would be same. In my case it was
$pValue[0] === '='
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) {
This will fix the "Trying to access array offset on value of type int" error. But you will also need to conduct a find and replace for curly braces throughout the PHPExcel code to address the "Array and string offset access syntax with curly braces is deprecated" error which also affects PHP ugrades to 7.4. I simply replaced them with "[" and "]" everywhere and everything is working fine again.
it works! love you!
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) {
This will fix the "Trying to access array offset on value of type int" error. But you will also need to conduct a find and replace for curly braces throughout the PHPExcel code to address the "Array and string offset access syntax with curly braces is deprecated" error which also affects PHP ugrades to 7.4. I simply replaced them with "[" and "]" everywhere and everything is working fine again.
When I was almost downgrading to PHP 7.3, thanks man this helped me
Any idea to solve this issue with PHP 7.4.3 & maatwebsite/excel version 2.1?
You would have to fork the deprecated phpexcel package and maintain the fork yourself.
} elseif (0 === strpos($pValue, '=') && strlen($pValue) > 1) {
strpos of bool, rly?
Just put this code after check to is_bool and is_float
Code is not part of this package, but of legacy PhpExcel
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) {
This will fix the "Trying to access array offset on value of type int" error. But you will also need to conduct a find and replace for curly braces throughout the PHPExcel code to address the "Array and string offset access syntax with curly braces is deprecated" error which also affects PHP ugrades to 7.4. I simply replaced them with "[" and "]" everywhere and everything is working fine again.
Thank You man. Loved it. Thankx @burello <3
The best thing to do is to update the PHPOffice/PhpSpreadsheet above 1.10 in your project - because then this Error will be fixed without having to manually edit the package codebase. So for me
composer require phpoffice/phpspreadsheet "^1.10"
fixed the problem.
i have this e'rror too
al klakkel
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) {
This will fix the "Trying to access array offset on value of type int" error. But you will also need to conduct a find and replace for curly braces throughout the PHPExcel code to address the "Array and string offset access syntax with curly braces is deprecated" error which also affects PHP ugrades to 7.4. I simply replaced them with "[" and "]" everywhere and everything is working fine again.
Thanks working for me !! orderimportexport.ocmod opencart 3x
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) {
This will fix the "Trying to access array offset on value of type int" error. But you will also need to conduct a find and replace for curly braces throughout the PHPExcel code to address the "Array and string offset access syntax with curly braces is deprecated" error which also affects PHP ugrades to 7.4. I simply replaced them with "[" and "]" everywhere and everything is working fine again.
Amazing, you saved me bro, thank you so much
replace this line 82:
} elseif ($pValue[0] === '=' && strlen($pValue) > 1) {
with the following:
} elseif (0 === strpos($pValue, '=') && strlen($pValue) > 1) {
working for me...

Please report errors within PhpSpreadsheet to PhpSpreadsheet.
Most helpful comment
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) {
This will fix the "Trying to access array offset on value of type int" error. But you will also need to conduct a find and replace for curly braces throughout the PHPExcel code to address the "Array and string offset access syntax with curly braces is deprecated" error which also affects PHP ugrades to 7.4. I simply replaced them with "[" and "]" everywhere and everything is working fine again.