zh_kostev_ext 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ module ControllerExtensions
|
|
3
3
|
def self.included(base)
|
4
4
|
base.class_eval do
|
5
5
|
private
|
6
|
+
require 'spreadsheet'
|
6
7
|
#This is method to create excel file with data and send it to user.
|
7
8
|
#
|
8
9
|
# Example:
|
@@ -12,14 +13,15 @@ module ControllerExtensions
|
|
12
13
|
# records = User.where(:super_admin => true).all #find record to export
|
13
14
|
# export_to_excel_prototype(records, ["First Name", "Last Name"], %w(first_name, last_name))
|
14
15
|
# end
|
16
|
+
# end
|
15
17
|
#
|
16
18
|
# You can specify file_name to provide name of excel file
|
17
19
|
#
|
18
|
-
# export_to_excel_prototype(records, ["First Name", "Last Name"], %w(first_name
|
20
|
+
# export_to_excel_prototype(records, ["First Name", "Last Name"], %w(first_name last_name), :file_name => "Super Admin excel export.xls")
|
19
21
|
#
|
20
22
|
# You can specify worksheet_name to provide name of worksheet in excel file
|
21
23
|
#
|
22
|
-
# export_to_excel_prototype(records, ["First Name", "Last Name"], %w(first_name
|
24
|
+
# export_to_excel_prototype(records, ["First Name", "Last Name"], %w(first_name last_name), :file_name => "Super Admin excel export.xls", :worksheet_name => "super admins")
|
23
25
|
#
|
24
26
|
def export_to_excel_prototype(records, column_names, model_column_names, options)
|
25
27
|
spreadsheet = StringIO.new
|
@@ -31,7 +33,7 @@ module ControllerExtensions
|
|
31
33
|
|
32
34
|
#create workbook and write data to it
|
33
35
|
def create_spreadsheet_for_export(records, column_names, model_column_names, options = {})
|
34
|
-
book = Spreadsheet::Workbook.new #create new book for writing
|
36
|
+
book = ::Spreadsheet::Workbook.new #create new book for writing
|
35
37
|
sheet = book.create_worksheet :name => (options[:worksheet_name].presence || options[:file_name].presence || 'Excel export') #create new sheet in book
|
36
38
|
sheet.row(0).concat column_names #write first row(column names)
|
37
39
|
records.each_with_index do |record, index|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zh_kostev_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
segments:
|
138
138
|
- 0
|
139
|
-
hash: -
|
139
|
+
hash: -491197677
|
140
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
141
|
none: false
|
142
142
|
requirements:
|