Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the start of the auto filter range to be defined #217

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

athena-metis
Copy link

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.

…the auto filter range.

Backwards Compatibility: Setting this option to true (old style) is already converted to 1 so backwards compability is still preserved, an additional is_int check is added for extra caution.
Use case: multi row headings where the auto filter dropdown row may be desired as the second row rather than the first
Usage: Setting the auto_filter option to 2 would result in the auto filter dropdowns and the data being filtered starting on row 2, this can be any number from 1-X and will offset the auto filter range respectively.
…ation (this is currently coarse in that it only allows for one override type for the whole row, not per column)

This is intended to allow for interim headers to be added similar to how headers are added
@japlavaren
Copy link

@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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants