Class: Spyro::ActionViewExtension::CollectionForHelper::Output::XLSX
- Inherits:
-
Base
- Object
- Base
- Spyro::ActionViewExtension::CollectionForHelper::Output::XLSX
show all
- Defined in:
- lib/spyro/collections/outputs/xlsx.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #t
Instance Method Details
#render ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/spyro/collections/outputs/xlsx.rb', line 20
def render
return "" if @unicollection.rows.empty?
filename = @unicollection.meta[:filename] || @unicollection.meta[:model_class] || "file"
xlsx_package = Axlsx::Package.new({})
wb = xlsx_package.workbook
wb.add_worksheet(name: filename) do |sheet|
sheet
render_body sheet
end
xlsx_package.to_stream.string
end
|
#render_body(sheet) ⇒ Object
14
15
16
17
18
|
# File 'lib/spyro/collections/outputs/xlsx.rb', line 14
def render_body sheet
@unicollection.rows.each do |row|
sheet.add_row row[:data].map(&:value)
end
end
|
9
10
11
12
|
# File 'lib/spyro/collections/outputs/xlsx.rb', line 9
def sheet
return unless @unicollection.meta[:data]
sheet.add_row @unicollection.meta[:data]
end
|