#Excel export autofit column width
21 messages · Page 1 of 1 (latest)
Nothing?
we dont control excel output, its a separate package
Thanks. So maybe I should use laravel-export by spartner
So have you done the getXlsxCellStyle() or getXlsxHeaderCellStyle() in the exporter class with openspout?
is that where you added setShouldWrapText() and setShouldShrinkToFit() ?
Yes. If setShouldWrapText() is set tu true, this happens:
But I would like this
Something like setAutoFitText()
i dont think there is an option in openspout, but there is an option to increase the width based on a fixed number
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
@civic raft did you solve it?
I did not. Right now I'm doing it manually on the excel.
public function getXlsxCellStyle(): Style
{
return (new Style())
->setShouldWrapText(false);
}
public function getXlsxHeaderCellStyle(): Style
{
return (new Style())
->setShouldWrapText(false);
}
Not working 😦
In a standard OpenSpout setup, thre is a way to configure the 'writer' options and have fixed widths there:
use OpenSpout\Writer\XLSX\Options;
$writerOptions = new Options();
$writerOptions->setColumnWidth(20, 1); //sets to 20, column 1
$writerOptions->setColumnWidth(30, 2); //sets to 30, column 2
.... and so forth...
so you can initialize as
$writer = new \OpenSpout\Writer\XLSX\Writer($writerOptions);
If only we could inject these type of writer options into the Filament Exporter ...I am looking for a way to do that right now.. I will come back here if find something useful .
Community friends, I am glad to let you know that I developed a solution and solved the issue above to inject those 'XLSX\Options' as needed. I am about to create a new PR for this enhancement; be back with the a link and solution in a bit 😀
Here it is my friends, hope this helps whoever else needs it https://github.com/filamentphp/filament/pull/14411
There you can see the two file modifications needed in case you want to test it out.
Since this is my first PR to an open source project ever , any feedback is truly appreciated, I tried my best and followed the procedures described in the Filament docs for contributing to the development, and that was harder for me than the actual solution to the problem 😂 Living and always learning something new!
If somebody else thinks this is a good idea, show some love in the pr above, please comment on it, maybe it could be implemented differently. I was even thinking in setting directly on the ExportColumn object itself, something like a ' ->XlsxWidth() ' in method in the object... anyway, in the meanwhile my users in one of my apps are happy that they can export pretty neat looking excel documents now without messing with column widths
I could certainly be wrong and I totally appreciate your efforts, but my question is what is the value to core filament about the appearance of a data export. In my mind the data is more important than the appearance of the data.