【问题标题】:How to protect individual cell using phpspreadsheet如何使用 phpspreadsheet 保护单个单元格
【发布时间】:2019-08-03 15:33:10
【问题描述】:

我想保护特定单元格内容不被修改。当我试图保护整张纸时,没问题。

$sheet->getProtection()->setSheet(true)->setDeleteRows(true);

但是,无法为单个单元格设置保护。我尝试了以下代码。

1

$sheet->protectCellsByColumnAndRow(0, 1, 100, 100, 'asdf');

2

$sheet->protectCells('A1','password',false);

提前致谢。

【问题讨论】:

    标签: phpspreadsheet phpoffice


    【解决方案1】:

    这里是解决方案。首先,启用工作表保护。然后,通过更改电子表格保护的默认样式来解锁所有单元格。之后,通过指定单元格的坐标锁定您想要的单元格。工作表保护仅适用于锁定的单元格。因此,当您打开该工作表时,您锁定的单元格将无法再编辑。

    $spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
    $spreadsheet->getDefaultStyle()->getProtection()->setLocked(false);
    $sheet->getStyle('A1')->getProtection()->setLocked(\PhpOffice\PhpSpreadsheet\Style\Protection::PROTECTION_PROTECTED);
    

    link-unlock all cellslink-lock individual cell 帮助了我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 2017-02-22
      • 2018-07-20
      • 1970-01-01
      相关资源
      最近更新 更多