How to export component as excel (axlsx) #1410
-
Hello, in my application there are some reports that can be display in html or excel and i use view component to build the html and caxlsx to build the excel. Is there any way to render the component in another format? How i can build a custom render? Example:
# report.xlsx.axlsx
wb = xlsx_package.workbook
wb.add_worksheet(name: "Report") do |sheet|
render_xlsx(Example::Component.new)
end |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @PedroAugustoRamalhoDuarte! Interesting use case you've got here. This feels like it might be more of a question for If you'd rather your axlsx logic in separate files, you could build a concern that defines Hope this is helpful to you as a starting point! |
Beta Was this translation helpful? Give feedback.
Hey @PedroAugustoRamalhoDuarte! Interesting use case you've got here. This feels like it might be more of a question for
caxlsx
folk, as adding this functionality seems no different to working with a plain old Ruby object. From what I can gather there, you may need to implement#to_xlsx
on your components so that they can be passed tocaxlsx
in this way.acts_as_xlsx
has a very generic implementation that you can take some inspiration from: https://github.com/caxlsx/acts_as_caxlsx/blob/master/lib/acts_as_xlsx/ar.rb#L48If you'd rather your axlsx logic in separate files, you could build a concern that defines
to_xlsx
to look for and read anxlsx.axlsx
folder from__dir__
, then evaluate it …