Вы можете добавить maatwebsite/excel
пакет для Laravel, который является оберткой вокруг phpoffice/phpspreadsheet
пакета.
Здесь приведены документы о том, как установить безопасность в электронной таблице на PhpSpreadsheet : https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#setting -security-on-a-электронные таблицы
См. расширение раздела документации laravel -excel , чтобы узнать, как вызывать PhpSpreadsheet методов для события или использования макроса.
Окончательный код будет выглядеть примерно так:
namespace App\Exports;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
class InvoicesExport implements WithEvents
{
/**
* @return array
*/
public function registerEvents(): array
{
return [
BeforeExport::class => function(BeforeExport $event) {
$event->writer->getDelegate()->getSecurity()->setLockWindows(true);
$event->writer->getDelegate()->getSecurity()->setLockStructure(true);
$event->writer->getDelegate()->getSecurity()->setWorkbookPassword("Your password");
];
}
}