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.

1 answer 1

Only by hand!

  1. Create a backup copy of the excel file.
  2. Change the file extension from .xlsx to .zip.
  3. Now extract the entire contents of the zip file.

Locate the xml of the target sheet. You will find it in the xl -> worksheets .

  1. Open the target sheet xml file in the xml editor.
  2. Find "sheetProtection" in this XML file and delete it.
  3. Save the edited xml file, and replace it with the old xml file in zip files.
  4. Change the extension from .zip to .xlsx.

Everything!