SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.23k stars 1.91k forks source link

[BUG] - ShouldAutoSize Doesn't working on version 3.1.27 #3055

Closed CarlosHLavezo closed 3 years ago

CarlosHLavezo commented 3 years ago

Prerequisites

Versions

Description

I was trying to use auto size in my sheet and it didn't work

Steps to Reproduce

Use the interface ShouldAutoSize in your sheet.

Expected behavior: The columns in the sheet will auto size the width

Actual behavior: The columns didn't auto size

Additional Information

I saw in the file vendor/maatwebsite/excel/src/Sheet.php the function below image

It test if ($dimension->getWidth() === -1) { but the function getWidth() return a float type, when I changed it for if ($dimension->getWidth() === -1.0) { the auto sizing start working again...

patrickbrouwers commented 3 years ago

Can you create a PR for that?

patrickbrouwers commented 3 years ago

No need anymore, I've pushed the fix myself. Thanks for reporting!

CarlosHLavezo commented 3 years ago

Oh! Thanks! I thought about opening the PR, but I decided to open this Issue before to validate... Anyway, I would like thanks for your attention.

aaronhuisinga commented 3 years ago

@patrickbrouwers could we get a new release tagged now that this is fixed?

badroumari commented 2 years ago

i have the same problem with ShouldAutoSize but i resolve it using those steps 1- go to vendor/maatwebsite/excel/src/Sheet.php 2-find function autoSize() and replace it with function below // Edited function
public function autoSize() { foreach ($this->buildColumnRange('A', $this->worksheet->getHighestDataColumn()) as $col) { $dimension = $this->worksheet->getColumnDimension($col); // Only auto-size columns that have not have an explicit width. if ($dimension->getWidth() === -1) { $dimension->setAutoSize(true);} elseif($dimension->getWidth() === -1.0){ $dimension->setAutoSize(true); } } }