Problem with function IOFactory::load(”)->getSheetByName(”)

Hi I am using the class IOFactory to read the pages of an xlsx file. I wrote these instructions:

$spreadsheet = IOFactory::load($filePath);
$sheetMale = $spreadsheet->getSheetByName('man');
$sheetFemale = $spreadsheet->getSheetByName('woman');
$sheetMale->toArray();
$sheetFemale->toArray();

Now the problem is that after creating with success the first array, the creation of the second blocks the code infinitly without genereting errors or messages. I want to precise that the ‘names’ and $filePath are correct

If it can be helpful I share the complete code too

<?php
namespace AppConsoleCommands;
use Exception;
use IlluminateConsoleCommand;
use PhpOfficePhpSpreadsheetIOFactory;

class ExtractExcelData extends Command
{
    public function extractDataFromExcel($filePath)
    {
        $spreadsheet = IOFactory::load($filePath);
        $sheetMale = $spreadsheet->getSheetByName('man');
        $sheetFemale = $spreadsheet->getSheetByName('woman');
        $rows = $sheetMale->toArray();
        $sheetFemale->toArray();
    }
    public function handle()
    {
        try {
            $filePath = storage_path('works.xlsx');
            $this->extractDataFromExcel($filePath);
            $this->info('Made well!');
        } catch (Exception $e) {
            $this->error("Error: " . $e->getMessage());
        }
    }
}