skip to Main Content

I’m trying to make a table that allows filters on phpspreadsheet.
I can already make the table, and if I remove the protection it will allow me to filter, but as soon as I put the protection, with or without password, it doesnt let me do it

Here is the part of the code for protection

Protection

//Add protection
$protection = $spreadsheet->getActiveSheet()->getProtection();
$protection->setPassword($worksheet_password);
$protection->setSheet(false);
$protection->setSort(false);
$protection->setInsertRows(false);
$protection->setFormatCells(false);
// Add filters to Table
$activeWorksheet->setAutoFilter('C6:P50');

Already put TRUE to all, false to Sheet…

2

Answers


  1. You literaly say don’t allow filter with this line:

    $protection->setSort(false);
    

    I would try with:

    $protection->setSort(true);
    
    Login or Signup to reply.
  2. In PhpSpreadsheetWorksheetProtection.php it says

    Autofilters are locked when sheet is protected, default true.

    I think what you need is

    $protection->setSheet(true);
    $protection->setAutoFilter(false)
    

    This is working for me

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search