我是Laravel Framework的新手。我试图给excel文件添加一个密码,这样它就可以用它打开了,但是文件打开时没有输入密码。
<?php
namespace App\Exports;
use App\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Events\BeforeExport;
class UserExport implements FromCollection, WithHeadings, ShouldAutoSize, WithEvents
{
protected $year;
protected $month;
public function __construct($year,$month)
{
$this->year = $year;
$this->month = $month;
}
public function registerEvents(): array
{
return [
BeforeExport::class => function(BeforeExport $event) {
$event->writer->getSecurity()->setLockWindows(true);
$event->writer->getSecurity()->setLockStructure(true);
$event->writer->getSecurity()->setWorkbookPassword("123456");
},
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->setRightToLeft(true);
},
];
}
}
找不到答案。我做错了什么?
发布于 2021-05-12 15:54:26
如果我没记错的话,PhpSpreadsheet只支持保护数据更改,不支持读取。如果你需要这样的东西,你可能需要使用密码保护的zip路径。您可以尝试PhpSpreadsheet社区中了解更多信息的人。
https://github.com/Maatwebsite/Laravel-Excel/issues/3152
https://github.com/Maatwebsite/Laravel-Excel/discussions/3151
https://stackoverflow.com/questions/66103399
复制相似问题