我们可以在Laravel-Excel出口中不可编辑。

发布于 2025-02-09 10:39:24 字数 485 浏览 2 评论 0原文

我正在使用maatwebsite \ excel下载Excel文件。下载文件时,我想制作指定列标题的标题行,仅阅读。下载后,没有人可以对标头进行任何更改。是否可以使列名称不正确?我寻找锁定功能或保护功能,但找不到答案。请帮忙。

我有registerevents()函数,其中我要指定所有编辑零件,例如

public function registerEvents(): array
{
    return [
        AfterSheet::class    => function(AfterSheet $event) {
            $event->sheet->getDelegate()->getStyle('A1:C1')->getFont()->setSize(16);
        },
    ];
}

我可以在此处或任何地方编写任何功能!?

I'm using Maatwebsite\Excel to download excel file. When the file downloaded I want to make header row which specify the column heading, read only. After downloading no one can make any change in headers. Is it Possible to do make column name un-editable ? I looked for lock function , or protect function but couldn't find answer. please help.

i have registerEvents() function where i'm specifying all the editing parts like ,

public function registerEvents(): array
{
    return [
        AfterSheet::class    => function(AfterSheet $event) {
            $event->sheet->getDelegate()->getStyle('A1:C1')->getFont()->setSize(16);
        },
    ];
}

is there any function i can write here or anywhere!?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

給妳壹絲溫柔 2025-02-16 10:39:25

该解决方案对我来说是使标头不可编辑的

$sheet->protectCells('A1:G1', 'PASSWORD');
$sheet->getStyle('A2:G10')->getProtection()->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED);
//A2:G10 is the range which can be editable 
$sheet->getDelegate()->getProtection()->setSheet(true);

This solution worked for me for making header uneditable

$sheet->protectCells('A1:G1', 'PASSWORD');
$sheet->getStyle('A2:G10')->getProtection()->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_UNPROTECTED);
//A2:G10 is the range which can be editable 
$sheet->getDelegate()->getProtection()->setSheet(true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文