0

Version:

composer.json :

    "require": {
        "php": "^8.0.1",
        "ext-zip": "*",
        "laravel/framework": "^8.25",
        "laravel/tinker": "^2.6",
        "laravel/ui": "^3.2",
        "phpoffice/phpspreadsheet": "^1.16"


Problem:

ErrorException Trying to access array offset on value of type null


After upgrading to Laravel 8 and PHP 8. I'm getting above error.

<?php

use PHPExcel_Reader_Excel2007;


$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load('/path/to/filename.xlsx'); // This line

5
  • 1
    That line you've highlighted doesn't try to access an array. Is there a stack trace? I'd guess the root cause is somewhere inside the library. Commented Feb 3, 2021 at 12:48
  • @ADyson Can I do something in phpspreadsheet instead of PHPExcel here. Commented Feb 3, 2021 at 12:49
  • 2
    If you're using PHPExcel_Reader_Excel2007 instead of phpspreadsheet, you may want to switch. PHPExcel is abandoned and may not work with PHP8. I'm not familiar with either package, so couldn't tell you how to switch. Commented Feb 3, 2021 at 12:50
  • Can I do something in phpspreadsheet ... I don't know. Your example simply opens a file. I've no idea what you're going to want to do after that. Try it and see if it meets your needs. Commented Feb 3, 2021 at 12:51
  • 3
    Actually, if you go to github.com/PHPOffice/PHPExcel it specifically tells you not to use PHPExcel anymore, and to use phpspreadsheet instead. So yeah it looks like you should be upgrading. Read github.com/PHPOffice/PhpSpreadsheet/blob/master/docs/topics/… as well. Commented Feb 3, 2021 at 12:53

3 Answers 3

4

Find the line of the error at the library file, in my case was some array that should not be null $attributes[$t] I've change it.

if ($attributes['t'] == 'array') { //from this
if (isset($attributes['t']) && $attributes['t'] == 'array') { //to this

the error dissapeared.

Sign up to request clarification or add additional context in comments.

Comments

0

it seems that the file is missing some property, what i did and that worked is i have the file with libreOffliceCal and i did a ctrl + s to save and when i tried again i no longer had this mistake

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I have solved this by replacing line 1688 in /PHPExcel/Classes/PHPExcel/Reader/Excel2007.php

Main:

$activeTab = intval($xmlWorkbook->bookViews->workbookView["activeTab"]); 

Replaced:

 $activeTab =isset($xmlWorkbook->bookViews->workbookView["activeTab"])? intval($xmlWorkbook->bookViews->workbookView["activeTab"]):"sheet1";  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.