Skip to content

Can't work $sheetData->toArray() if the .xlsx file sheet contains SWITCH() #963

@azuma560

Description

@azuma560

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

You can read sheetData by this.

    public function getSheetData($sheetName)
    {
        $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
        $spreadsheet = $reader->load("/var/www/storage/app/upload_file.xlsx");
        $sheetData = $spreadsheet->getSheetByName($sheetName)->toArray();
         return $sheetData;
    }

What is the current behavior?

ErrorException (E_ERROR)
sheet!A2 -> Formula Error: Unexpected

What are the steps to reproduce?

A2
=SWITCH(B2,0,"ja",1,"en",2,"cs",3,"ko",4,"vi")
B2
=2

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php
namespace App\Http\Controllers;

class ReadController
{
    private $spreadsheet = array();

    public function __construct()
    {
        $this->read();
    }

    private function read()
    {
        $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
        $this->spreadsheet = $reader->load("/var/www/storage/app/upload_file.xlsx");
    }

    public function getSheetData($sheetName)
    {
        //error at this code
        $sheetData = $this->spreadsheet->getSheetByName($sheetName)->toArray();
        return $sheetData;
    }

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet - latest
PHP - 7.2
Laravel - 5.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions