aVadim483 / fast-excel-writer

Lightweight and very fast XLSX Excel Spreadsheet Writer in PHP
MIT License
142 stars 26 forks source link

setColWidthAuto resizer not working 100% effectively #57

Closed elidon555 closed 1 month ago

elidon555 commented 2 months ago

SetColWidthAuto doesn't work correctly when you also use setAutofilter

$worksheet->writeHeader($headers);
$worksheet->setAutofilter();
$worksheet->setColWidthAuto(self::getColumnRange($headers));

Filter applied below: image image

Filter not applied below: (As u can see last character is not visible) image

Desired result below by manually double-clicking between the two columns image

Is this possible? PHPSpreadsheet does this very well

aVadim483 commented 2 months ago

Here's an explanation of how PhpSpreadsheet calculates column width: https://github.com/PHPOffice/PhpSpreadsheet/issues/2750

The GD method is definitely not suitable, because it will be very slow on large tables. The FastExcelWriter library is designed to create Excel files very quickly, and cannot use this method. But I will look into PhpSpreadsheet alternative method

elidon555 commented 2 months ago

Here's an explanation of how PhpSpreadsheet calculates column width: PHPOffice/PhpSpreadsheet#2750

The GD method is definitely not suitable, because it will be very slow on large tables. The FastExcelWriter library is designed to create Excel files very quickly, and cannot use this method. But I will look into PhpSpreadsheet alternative method

Ah I see, thank you for the explanation! I suppose it's not possible to add extra width after this automatic calculation?

aVadim483 commented 1 month ago

I have improved the column width calculation, please update to 5.3 and check it