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

Combining the setAutoFilter and setAutoSize #2413

Closed
cwolcott opened this issue Nov 24, 2021 · 3 comments
Closed

Combining the setAutoFilter and setAutoSize #2413

cwolcott opened this issue Nov 24, 2021 · 3 comments

Comments

@cwolcott
Copy link

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.

@cwolcott
Copy link
Author

Does anyone have any thoughts on this. I know the current workaround is not correct, but it helps be get past the issue for the time being.

Shared/Font.php (line 249), the multiple was 1.07. I changed it to 3.5 for fun.

        if (!$approximate) {
            $columnWidthAdjust = ceil(self::getTextWidthPixelsExact('n', $font, 0) * 3.5);

@cwolcott
Copy link
Author

cwolcott commented Apr 29, 2022

@MarkBaker Thank you very much that makes it a lot better. I would suggest increasing the adjustment from 3 to 5.
Line 256 str_repeat('n', 1 * ($filterAdjustment ? 5 : 1)),
Line 273 str_repeat('n', 1 * ($filterAdjustment ? 5 : 1)),

With a value of 3 the filer dropdown icon is still very tight.
image

Looks better with a value of 5
image

@MarkBaker
Copy link
Member

Hmm, 3 should be adequate for plain text; I may do a little tweak to test for bold or italic and use 5 in those cases

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

No branches or pull requests

2 participants