如何解决在 Laravel 中为 Excel 文件添加密码
我是 Laravel 框架的新手。我尝试向 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);
},];
}
}
找不到答案。我做错了什么?
解决方法
如果我没记错的话 PhpSpreadsheet 只支持保护数据更改,不支持读取。如果你需要这样的东西,你可能需要走密码保护的拉链路线。你可以试试 PhpSpreadsheet 社区中知道更多的人。
https://github.com/Maatwebsite/Laravel-Excel/issues/3152
https://github.com/Maatwebsite/Laravel-Excel/discussions/3151
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。