randym / activeadmin-axlsx

ActiveAdmin plugin using Axlsx for adding Excel (xlsx) download links for your resources
MIT License
82 stars 134 forks source link

XLS format definition #2

Closed bolshakov closed 11 years ago

bolshakov commented 11 years ago

It would be great if your gem supports the same syntax as ActiveRecord use for CSV format definition http://activeadmin.info/docs/4-csv-format.html

randym commented 11 years ago

Hi @bolshakov

I've intentionally gone with a subtractive declaration as I find for the majority of the reporting I do I am usually removing just a few items, and it sames me keystrokes not having to explicitly state each column I want in the report.

However, I am willing to invert this behaviour so that it matches the CSV exporter if the majority of users would rather have it that way.

Anyone else out there who wants this to work like the CSV DSL?

alexey-chernikov commented 11 years ago

Yep, I think CSV DSL is much better. I have problem with models and many fields within it (> 20): it quite a boring way to substract all columns, which I do not need. For users there is also problem: many system information should not be exported (password hash, confirmation tokens and so on), so it really difficult to substract all fields. I think declaring "that I need" is better, than declaring "that I do not need".

th1988 commented 11 years ago

+1

baxang commented 11 years ago

+1 to the CSV DSL.

Firstly, it is a more safer way to prevent any unwanted columns are exported. Secondly, it gives a better compatibility that the same code for CSV formatting can be used for XSLX.

By the way, making my previous CSV DSL to the one for XSLX wasn't that hard that I just needed to declare clear_columns on the top of the DSL block. The line conveniently remove all the columns so I can just add columns that I need to include.

  xlsx do
    clear_columns
    column ....
    ..
esa-pia commented 11 years ago

+1

randym commented 11 years ago

I've added a DSL item to specify that you want to whitelist your attributes that internally does exactly what @baxang has shown above as it is a bit more explicit.

In your builder config you simply need to specify

xlsx do 
  whitelist
  # add columns you want
end

This will be shipped in the next release. If you want it now, or are willing to do a pre-release verification please have a go at what is currently on master.