Skip to content

Combining the setAutoFilter and setAutoSize #2413

@cwolcott

Description

@cwolcott

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

I initially reported this in #2274, but then prematurely closed it when I thought it was fixed.

I would have hoped that using the setAutoSize function would have appropriately determined the correct size for a column when the function setAutoFilter had already be applied.

        Font::setTrueTypeFontPath("/usr/share/fonts/msttcore/");
        Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_EXACT);
        ...
        // Apply filtering capability to the worksheet
        $worksheet->setAutoFilter($worksheet->calculateWorksheetDimension());

        // Apply auto size to all columns
        foreach (range('A',$workSheetMaxColumns) as $col) { $worksheet->getColumnDimension($col)->setAutoSize(true); }
        ...

What is the current behavior?

It does not seem to take into account the filter icon shown in the column. See attached images
AutoFilter AutoSize NotCalculated

When I double click on the column seperator in excel it widens the column widths to my satisfaction.
AutoFilter AutoSize ExcelCalculated

Which versions of PhpSpreadsheet and PHP are affected?

version 1.18.0+

I thought this was fixed, but I guess I fixed it myself and then lost the fix when upgrading from 1.18.0 to 1.20.0. I am trying to figure out what I did to fix it.

Before in 1.18.0 with may fix:
image

After in 1.20.0 after losing my fix:
image

You can see that the columns are not taking in account the filter icon.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions