0

i want to read xlsx file and write back some data to the file like below :

try {
 $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();        
 $spreadsheet = $reader->load('CatagoryEng.xlsx');
 dd($spreadsheet);
} catch (\Exception $ex) {
 dd($ex);
} 

the above code works fine in local but in server it gives the below exception

ErrorException {#1444 ▼
  #message: "Trying to access array offset on value of type null"
  #code: 0
  #file: "/home/ar../vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Reader/Xlsx/Styles.php"
  #line: 133
  #severity: E_NOTICE
  trace: {▶}
}

other information :

  • the some package "phpoffice/phpspreadsheet": "^1.4" used both in local and server.
  • php version is "php": "^7.1.3"
  • laravel version is "laravel/framework": "5.6.*"
  • So which line is failing exactly? Does `$reader` fail or maybe `$spreadsheet`? What the heck is `dd()`? – MonkeyZeus Nov 18 '20 at 19:23
  • `dd()` - https://laravel.com/docs/8.x/helpers#method-dd. I've always heard it referred to as, "dump 'n die". – waterloomatt Nov 18 '20 at 19:25
  • Are you PHP and Laravel versions the same on both servers? – waterloomatt Nov 18 '20 at 19:34
  • Great, so is `$reader` failing or is it `$spreadsheet`? – MonkeyZeus Nov 18 '20 at 19:46
  • @waterloomatt yes both are same – Mohammad Zubair Akrami Nov 18 '20 at 19:47
  • @MonkeyZeus @MonkeyZeus i think the `reader ` fail because but when run it in server it looks like `Xlsx {#1086 ▼ -referenceHelper: ReferenceHelper {#191} #readFilter: DefaultReadFilter {#1094} #securityScanner: XmlScanner {#1095 ▶} } ` – Mohammad Zubair Akrami Nov 18 '20 at 19:49
  • @MonkeyZeus the `reader` object should looks like `PhpOffice\PhpSpreadsheet\Reader\Xlsx {#2244 ▼ -referenceHelper: PhpOffice\PhpSpreadsheet\ReferenceHelper {#323} #readDataOnly: false #readEmptyCells: true #includeCharts: false #loadSheetsOnly: null #readFilter: PhpOffice\PhpSpreadsheet\Reader\DefaultReadFilter {#2281} #fileHandle: null #securityScanner: PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner {#2280 ▶} }` – Mohammad Zubair Akrami Nov 18 '20 at 19:51
  • 1
    Okay, so comment out every line and uncomment them one by one until you find the failure. – MonkeyZeus Nov 18 '20 at 19:53
  • Try Maatwebsite/Laravel-Excel they have made working with excel super easy in Laravel. – Mudit Gulgulia Nov 18 '20 at 20:28
  • may be the issue is because of file permissions on server the reader may not be able to access file as read-write mode – bhucho Nov 19 '20 at 05:23

0 Answers0