Tell me how to open an excel book password protected? On the Internet could not find information is mainly proposed to set the password of the book. Trying to open like this
use PhpOffice\PhpSpreadsheet\IOFactory; $imputFile = Yii::getAlias('@backend/web/uploads/') . "m.xlsx"; $spreadsheet = IOFactory::load($imputFile); $spreadsheet->getSecurity()->setLockWindows(true); $spreadsheet->getSecurity()->setLockStructure(true); $spreadsheet->getSecurity()->setWorkbookPassword("922104"); $sheet = $spreadsheet->getActiveSheet(); echo $sheet->getCell('C10')->getValue() . "\n"; If you remove the password from the book then everything is read and displayed on the screen, you should put it and get an error: Your requested sheet index: -1 is out of bounds. The actual number of sheets is 0.