#Excel export autofit column width

21 messages · Page 1 of 1 (latest)

civic raft
#

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.

shell steepleBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

civic raft
#

Nothing?

manic forge
#

we dont control excel output, its a separate package

civic raft
manic forge
#

So have you done the getXlsxCellStyle() or getXlsxHeaderCellStyle() in the exporter class with openspout?

#

is that where you added setShouldWrapText() and setShouldShrinkToFit() ?

civic raft
#

Yes. If setShouldWrapText() is set tu true, this happens:

#

But I would like this

#

Something like setAutoFitText()

manic forge
#

i dont think there is an option in openspout, but there is an option to increase the width based on a fixed number

civic raft
lethal locust
#

@civic raft did you solve it?

civic raft
lethal locust
haughty fractal
#

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 .

haughty fractal
#

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 😀

haughty fractal
#

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!

GitHub

Description
This PR adds a getXlsxOptions() method to the Exporter class to allow users to further customize their exported XLSX documents, such as column widths, or any other OpenSpout\Writer\XLSX...

haughty fractal
#

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

trim schooner
#

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.