Open athena-metis opened 6 years ago
@athena-metis thank you for this PR. It helped me a lot to fing out how to create autofilter on second line. It is working fine but I have problem when I combine auto filter on second line with cell merge on first line. Created xlsx file can not be opened in Excel - I am getting Excel could not open xlsx-autofilter.xlsx because some content is unreadable.
. I am able to open it with LibreOffice without any problems but I need to be working with Excel 2016 too.
I have no idea what can be wrong with it maybe cou have hint:
Changed ex09-autofilter.php
<?php
set_include_path( get_include_path().PATH_SEPARATOR."..");
include_once("xlsxwriter.class.php");
$chars = 'abcdefgh';
$sheetName = 'Sheet1';
$writer = new XLSXWriter();
$writer->writeSheetHeader($sheetName, ['Header' => '@'], ['auto_filter' => 2, 'widths' => [15, 15, 30]]);
// when I comment following line everything is working ok
$writer->markMergedCell($sheetName, $start_row=0, $start_col=0, $end_row=0, $end_col=1);
$writer->writeSheetRow($sheetName, ['col-string', 'col-numbers', 'col-timestamps']);
$writer->setSheetColumnTypes($sheetName, ['string', 'integer', 'datetime']);
for($i=0; $i<1000; $i++)
{
$writer->writeSheetRow('Sheet1', array(
str_shuffle($chars),
rand()%10000,
date('Y-m-d H:i:s',time()-(rand()%31536000))
));
}
$writer->writeToFile('xlsx-autofilter.xlsx');
These changes use a numeric value assigned to the auto_filter option as the starting row for the auto filter range. This allows for cases where there may be multiple heading rows (categories and individual column labels) where you want the filtering to start from the second row rather than the first. The current start position is hard coded.
The value passed to auto_filter is currently passed through intval so an existing true option value would be evaluated to 1 meaning backwards compatibility is preserved.