Class: XlsxExportService
- Inherits:
-
Object
- Object
- XlsxExportService
- Includes:
- DataExportHelper
- Defined in:
- app/models/rails_data/export_services/xlsx_export_service.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#sheet ⇒ Object
readonly
Returns the value of attribute sheet.
-
#table_list ⇒ Object
readonly
Returns the value of attribute table_list.
Instance Method Summary collapse
- #cached_xlsx ⇒ Object
- #direct_xlsx ⇒ Object
-
#initialize(table_list: nil, data_list: nil, params: {}, headers: []) ⇒ XlsxExportService
constructor
A new instance of XlsxExportService.
Methods included from DataExportHelper
#convert_parameters, #field_result, #footer_result, #header_result
Constructor Details
#initialize(table_list: nil, data_list: nil, params: {}, headers: []) ⇒ XlsxExportService
Returns a new instance of XlsxExportService.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/rails_data/export_services/xlsx_export_service.rb', line 8 def initialize(table_list: nil, data_list: nil, params: {}, headers: []) if table_list @table_list = table_list @data_list = table_list.data_list @headers = headers.presence || table_list.headers convert_parameters(params) elsif data_list @data_list = data_list @headers = headers convert_parameters(params) end @config_table = @data_list.config_table @io = StringIO.new @workbook = WriteXLSX.new(@io) @sheet = @workbook.add_worksheet end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'app/models/rails_data/export_services/xlsx_export_service.rb', line 4 def headers @headers end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'app/models/rails_data/export_services/xlsx_export_service.rb', line 4 def params @params end |
#sheet ⇒ Object (readonly)
Returns the value of attribute sheet.
4 5 6 |
# File 'app/models/rails_data/export_services/xlsx_export_service.rb', line 4 def sheet @sheet end |
#table_list ⇒ Object (readonly)
Returns the value of attribute table_list.
4 5 6 |
# File 'app/models/rails_data/export_services/xlsx_export_service.rb', line 4 def table_list @table_list end |
Instance Method Details
#cached_xlsx ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/rails_data/export_services/xlsx_export_service.rb', line 38 def cached_xlsx sheet.write_row(0, 0, table_list.headers) table_list.table_items.each_with_index do |table_item, index| sheet.write_row(index + 1, 0, table_item.fields) end sheet.write_row table_list.table_items_count + 1, 0, table_list. @workbook.close @io.string end |
#direct_xlsx ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/rails_data/export_services/xlsx_export_service.rb', line 26 def direct_xlsx sheet.write_row(0, 0, headers) @config_table.collection.call(@params).each_with_index do |object, index| row = field_result(object, index) sheet.write_row(index + 1, 0, row) end @workbook.close @io.string end |