Module: Axlsx::Ar::SingletonMethods
- Defined in:
- lib/axlsx/ar.rb
Overview
Singleton methods for the mixin
Instance Method Summary (collapse)
-
- (Object) to_xlsx(number = :all, options = {})
Maps the AR class to an Axlsx package options are passed into AR find.
Instance Method Details
- (Object) to_xlsx(number = :all, options = {})
Maps the AR class to an Axlsx package options are passed into AR find
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/axlsx/ar.rb', line 32 def to_xlsx(number = :all, = {}) row_style = .delete(:style) header_style = .delete(:header_style) || row_style types = .delete(:types) data = [*find(number, )] data.compact! data.flatten! columns = data.first.attributes.keys p = Package.new row_style = p.workbook.styles.add_style(row_style) unless row_style.nil? header_style = p.workbook.styles.add_style(header_style) unless header_style.nil? p.workbook.add_worksheet(:name=>table_name.humanize) do |sheet| sheet.add_row columns, :style=>header_style data.each do |r| sheet.add_row r.attributes.values, :style=>row_style, :types=>types end end p end |