F
Filament2mo ago
Rome

Excel export autofit column width

Is there any way to autofit column width to contain all column data on excel export? I tried with setShouldWrapText() and setShouldShrinkToFit() with no luck.
13 Replies
Rome
Rome2mo ago
Nothing?
Dan Harrin
Dan Harrin2mo ago
we dont control excel output, its a separate package
Rome
Rome2mo ago
Thanks. So maybe I should use laravel-export by spartner
Dan Harrin
Dan Harrin2mo ago
So have you done the getXlsxCellStyle() or getXlsxHeaderCellStyle() in the exporter class with openspout? is that where you added setShouldWrapText() and setShouldShrinkToFit() ?
Rome
Rome2mo ago
Yes. If setShouldWrapText() is set tu true, this happens:
No description
Rome
Rome2mo ago
But I would like this
No description
Rome
Rome2mo ago
Something like setAutoFitText()
Dan Harrin
Dan Harrin2mo ago
i dont think there is an option in openspout, but there is an option to increase the width based on a fixed number
Rome
Rome2mo ago
Maybe setting page setup? There is an option fitToWidth but i dont know if that is what im searching for https://github.com/openspout/openspout/blob/4.x/docs/documentation.md#page-setup
GitHub
openspout/docs/documentation.md at 4.x · openspout/openspout
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way - openspout/openspout
Gush
Gush2mo ago
@Rome did you solve it?
Rome
Rome2mo ago
I did not. Right now I'm doing it manually on the excel.
Gush
Gush2mo ago
public function getXlsxCellStyle(): Style
{
return (new Style())
->setShouldWrapText(false);
}

public function getXlsxHeaderCellStyle(): Style
{
return (new Style())
->setShouldWrapText(false);
}
public function getXlsxCellStyle(): Style
{
return (new Style())
->setShouldWrapText(false);
}

public function getXlsxHeaderCellStyle(): Style
{
return (new Style())
->setShouldWrapText(false);
}
Rome
Rome2mo ago
Not working 😦