filament icon indicating copy to clipboard operation
filament copied to clipboard

Xlsx style cell column

Open gpibarra opened this issue 8 months ago • 4 comments

Description

Currently, you can style the header and the rest of the cells (separately). This PR allows you to format each of the exported columns (value cells only; header row cells are not included). When you style a column, you can call the function multiple times, and each style (or callback) is saved in an array. When obtaining the column style, all styles are calculated and merged. This is designed to allow styling, for example, in the make/setup function for potential new column classes that extend the ExportColumn class. Styles (or callbacks) can be fixed, meaning they do not depend on the cell value. They will be cached to improve performance and avoid merging each row of data in the export file. Additionally, you can assign a style based on the cell value, which will be executed on each row of data (OpenSpout does not support Excel conditional formatting).

Functional changes

  • [x] Code style has been fixed by running the composer cs command.
  • [x] Changes have been tested to not break existing functionality.
  • [x] Documentation is up-to-date.

gpibarra avatar Apr 16 '25 18:04 gpibarra

In the documentation, I corrected a change to this PR: https://github.com/filamentphp/filament/pull/16025 It wasn't clear whether the function needed to be renamed or not, but only the documentation had been changed. Feel free to rename the function.

gpibarra avatar Apr 16 '25 18:04 gpibarra

At this point, maybe the entire writer creation process should just be moved onto the Exporter class, so it can be overriden in any way instead of needing all these new config methods

danharrin avatar Apr 17 '25 10:04 danharrin

I agree. Initially, I only called getStyle once before the record loop. But the fact that the library doesn't support conditional formatting motivated me to create an additional method. I think it's perhaps too much customization for the default case. I would leave the basic style and not the one that depends on the value (called for each cell in each row).

Regarding the writer depending on the exporter, I don't see it as a problem, but if not, it's not that difficult to override the logic. These changes I proposed were born from a project with Filament v3, and I modified the writer logic with a bind from a service provider. It's not complicated.

gpibarra avatar Apr 19 '25 09:04 gpibarra

Can yon move all the writer logic into the exporter class then please? We could even remove that configureXlsxWriterBeforeClose() method tbh

danharrin avatar Apr 19 '25 11:04 danharrin

Hi, are you able to making the suggested changes so we can merge the PR?

danharrin avatar May 21 '25 08:05 danharrin

Sorry for the delay, I'll get back to working on this PR tomorrow.

gpibarra avatar May 21 '25 10:05 gpibarra

Replaced by 476b92c7f1a04dc29066eb271bd498f8d25b6a6c

danharrin avatar Jun 02 '25 12:06 danharrin