mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 663 forks source link

auto_filter doesn't work when there are rows before table header #346

Open hypersonic64 opened 1 year ago

hypersonic64 commented 1 year ago

Hi, I need a sheet with two rows followed by a table. This table has a header with filter. This is what it should look like: table_template You can see the table header with filtering active in row 3.

But table filtering only works for me without the rows above the table. As soon as I add the two rows using $writer->writeSheetRow() then the table header no longer shows filter option. I'm using the 2023-06-02 release.

This is the code for the table only with correct set filter: $writer = new XLSX_Writer(); $sheetName = 'TEST'; $rowFormat = ['height' => 20, 'font-size'=>10]; $formatList = ['col1'=>'string', 'col2'=>'string']; $colOptions = ['auto_filter' => true, 'freeze_rows' => 1, 'suppress_row' => false]; $writer->writeSheetHeader($sheetName, $formatList, $colOptions); $writer->writeSheetRow($sheetName, ['aaa', 'bbb'], $rowFormat); $writer->writeSheetRow($sheetName, ['ccc', 'ddd'], $rowFormat); $writer->writeToFile($file); table

But when I try to insert the two rows above the table, then the filtering is no longer active in the table header. As far as I know I need to write another header for inserting rows above a table, so my code looks like this: $writer = new XLSX_Writer(); $colOptions = ['suppress_row' => true]; $writer->writeSheetHeader($sheetName, ['string'], $colOptions); $writer->writeSheetRow($sheetName, ['HEAD'], ['height' => 30, 'font-size'=>20,'font-style'=>'bold']); $writer->writeSheetRow($sheetName, ['SUBHEAD'], ['height' => 30, 'font-size'=>14,'font-style'=>'bold']); $rowFormat = ['height' => 20, 'font-size'=>10]; $formatList = ['col1'=>'string', 'col2'=>'string']; $colOptions = ['auto_filter' => true, 'freeze_rows' => 1, 'suppress_row' => false]; $writer->writeSheetHeader($sheetName, $formatList, $colOptions); $writer->writeSheetRow($sheetName, ['aaa', 'bbb'], $rowFormat); $writer->writeSheetRow($sheetName, ['ccc', 'ddd'], $rowFormat); $writer->writeToFile($file);

The result is: table_with_headline No filtering anymore.

Any hints? Thanks Hyper

hypersonic64 commented 1 year ago

Anybody?