spreadsheet_architect 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +93 -37
- data/lib/spreadsheet_architect.rb +141 -91
- data/lib/spreadsheet_architect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07793c007586700df1c0720d23cc124e9293551
|
4
|
+
data.tar.gz: ccadd4b8c35e81f68a589b5c4623b418d1fc94ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6bb10fa48dad7fc1ef0f2bd2d30e979150432a6e304dcfb5eec183ad5d2511f09f5a116400c0f718b011b8b5873a31866adf172b5a7a97525d281e7c8a98d7
|
7
|
+
data.tar.gz: 50bb9b635edc7d098a0ac07e4438af5ad865820786ac1b6a70a2daf5a329733f5f24a50d1350aa87eca9be468fb5d54034574a344e8443a6fd3db66ac4a9c6e6
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
3
|
|
4
|
+
- **April.29.2016**: 1.4.0
|
5
|
+
- Add to_xlsx, to_ods, & to_csv to SpreadsheetArchitect model for direct calling by passing in cell data
|
6
|
+
- **April.21.2016**: 1.3.0
|
7
|
+
- Add ability to create class/model and project option defaults
|
4
8
|
- **March.25.2016**: 1.2.5
|
5
9
|
- Fix each_with_index bug
|
6
10
|
- **March.24.2016**: 1.2.4
|
data/README.md
CHANGED
@@ -1,24 +1,38 @@
|
|
1
1
|
# Spreadsheet Architect
|
2
2
|
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=VKY8YAWAS5XRQ&lc=CA&item_name=Weston%20Ganger&item_number=spreadsheet_architect¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHostedGuest" target="_blank" title="Donate"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="Donate"/></a>
|
3
3
|
|
4
|
-
|
4
|
+
Spreas
|
5
|
+
|
6
|
+
Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets easily from ActiveRecord relations, Plain Ruby classes, or predefined data.
|
7
|
+
|
8
|
+
Key Features:
|
9
|
+
|
10
|
+
- Can generate headers & columns from ActiveRecord column_names, or a Class/Model's spreadsheet_columns method, or one creation with 2D array of data
|
11
|
+
- Plain Ruby support
|
12
|
+
- Plain from ActiveRecord relations or Ruby Objects from models ActiveRecord, or 2d Array Data
|
13
|
+
- Easily style headers and rows
|
14
|
+
- Model/Class or Project specific defaults
|
15
|
+
- Simple to use ActionController renderers
|
5
16
|
|
6
17
|
Spreadsheet Architect adds the following methods to your class:
|
7
18
|
```ruby
|
8
|
-
#
|
9
|
-
Post.to_xlsx(data: posts_array)
|
10
|
-
Post.to_ods(data: posts_array)
|
11
|
-
Post.to_csv(data: posts_array)
|
12
|
-
|
13
|
-
# Rails
|
19
|
+
# Rails ActiveRecord Model
|
14
20
|
Post.order(name: :asc).where(published: true).to_xlsx
|
15
21
|
Post.order(name: :asc).where(published: true).to_ods
|
16
22
|
Post.order(name: :asc).where(published: true).to_csv
|
17
|
-
```
|
18
|
-
|
19
|
-
## Note: Breaking Changes in 1.1.0
|
20
|
-
The `spreadsheet_columns` method has been moved from the class to the instance. So now you can use string interpolation in your values. Please re-read the Model section below to see the changes. The side effect of this is if you are using the spreadsheet_columns option directly on the .to_* methods.
|
21
23
|
|
24
|
+
# Plain Ruby Class
|
25
|
+
Post.to_xlsx(instances: posts_array)
|
26
|
+
Post.to_ods(instances: posts_array)
|
27
|
+
Post.to_csv(instances: posts_array)
|
28
|
+
|
29
|
+
# One Time Usage
|
30
|
+
headers = ['Col 1','Col 2','Col 3']
|
31
|
+
data = [[1,2,3], [4,5,6], [7,8,9]]
|
32
|
+
SpreadsheetArchitect.to_xlsx(data: data, headers: headers)
|
33
|
+
SpreadsheetArchitect.to_ods(data: data, headers: headers)
|
34
|
+
SpreadsheetArchitect.to_csv(data: data, header: false)
|
35
|
+
```
|
22
36
|
|
23
37
|
# Install
|
24
38
|
```ruby
|
@@ -26,7 +40,7 @@ gem install spreadsheet_architect
|
|
26
40
|
```
|
27
41
|
|
28
42
|
|
29
|
-
# Setup
|
43
|
+
# Class/Model Setup
|
30
44
|
|
31
45
|
### Model
|
32
46
|
```ruby
|
@@ -106,7 +120,7 @@ class PostsController < ActionController::Base
|
|
106
120
|
respond_to do |format|
|
107
121
|
format.html
|
108
122
|
format.xlsx { render xlsx: @posts.to_xlsx(headers: false) }
|
109
|
-
format.ods { render ods: Post.to_odf(
|
123
|
+
format.ods { render ods: Post.to_odf(instances: @posts) }
|
110
124
|
format.csv{ render csv: @posts.to_csv(headers: false), file_name: 'articles' }
|
111
125
|
end
|
112
126
|
end
|
@@ -115,6 +129,7 @@ end
|
|
115
129
|
|
116
130
|
### Method 2: Save to a file manually
|
117
131
|
```ruby
|
132
|
+
# Ex. with ActiveRecord realtion
|
118
133
|
File.open('path/to/file.xlsx') do |f|
|
119
134
|
f.write{ Post.order(published_at: :asc).to_xlsx }
|
120
135
|
end
|
@@ -127,35 +142,76 @@ end
|
|
127
142
|
|
128
143
|
# Ex. with plain ruby class
|
129
144
|
File.open('path/to/file.xlsx') do |f|
|
130
|
-
f.write{ Post.to_xlsx(
|
145
|
+
f.write{ Post.to_xlsx(instances: posts_array) }
|
131
146
|
end
|
132
|
-
```
|
133
|
-
|
134
|
-
# Method Options
|
135
|
-
|
136
|
-
### to_xlsx, to_ods, to_csv
|
137
|
-
**data** - *Array* - Mainly for Plain Ruby objects pass in an array of instances. Optional for ActiveRecord relations, you can just chain the method to the end of your relation. If Plain Ruby object it defaults to the instances `to_a` method.
|
138
|
-
|
139
|
-
**headers** - *Boolean* - Default: true - Pass in false if you do not want a header row.
|
140
147
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
148
|
+
# Ex. One time Usage
|
149
|
+
File.open('path/to/file.xlsx') do |f|
|
150
|
+
headers = ['Col 1','Col 2','Col 3']
|
151
|
+
data = [[1,2,3], [4,5,6], [7,8,9]]
|
152
|
+
f.write{ SpreadsheetArchitect::to_xlsx(data: data, headers: headers) }
|
153
|
+
end
|
154
|
+
```
|
145
155
|
|
146
|
-
|
156
|
+
# Method & Options
|
157
|
+
|
158
|
+
<br>
|
159
|
+
#### `.to_xlsx` - (on custom class/model)
|
160
|
+
|Option|Type|Default|Notes|
|
161
|
+
|---|---|---|---|
|
162
|
+
|**spreadsheet_columns**|Array| AR Model column_names | Required if `spreadsheet_columns` not defined on class except with ActiveRecord models which default to the `column_names` method. Will override models `spreadsheet_columns` method |
|
163
|
+
|**instances**|Array| |**Required for Non-ActiveRecord classes** Array of class/model instances.|
|
164
|
+
|**headers**|Boolean|`true`|Pass false to skip the header row.|
|
165
|
+
|**sheet_name**|String|Class name||
|
166
|
+
|**header_style**|Hash|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`||
|
167
|
+
|**row_style**|Hash|`{background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|Styles for non-header rows.|
|
147
168
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
169
|
+
<br>
|
170
|
+
#### `.to_ods` - (on custom class/model)
|
171
|
+
|Option|Type|Default|Notes|
|
172
|
+
|---|---|---|---|
|
173
|
+
|**spreadsheet_columns**|Array| AR Model column_names | Required if `spreadsheet_columns` not defined on class except with ActiveRecord models which default to the `column_names` method. Will override models `spreadsheet_columns` method |
|
174
|
+
|**instances**|Array| |**Required for Non-ActiveRecord classes** Array of class/model instances.|
|
175
|
+
|**headers**|Boolean|`true`|Pass false to skip the header row.|
|
176
|
+
|**sheet_name**|String|Class name||
|
177
|
+
|**header_style**|Hash|`{color: "000000", align: :center, font_size: 10, bold: true}`|Note: Currently only supports these options (values can be changed though)|
|
178
|
+
|**row_style**|Hash|`{color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently only supports these options (values can be changed though)|
|
179
|
+
|
180
|
+
<br>
|
181
|
+
#### `.to_csv` - (on custom class/model)
|
182
|
+
|Option|Type|Default|Notes|
|
183
|
+
|---|---|---|---|
|
184
|
+
|**spreadsheet_columns**|Array| AR Model column_names | Required if `spreadsheet_columns` not defined on class except with ActiveRecord models which default to the `column_names` method. Will override models `spreadsheet_columns` method |
|
185
|
+
|**instances**|Array| |**Required for Non-ActiveRecord classes** Array of class/model instances.|
|
186
|
+
|**headers**|Boolean|`true`|Pass false to skip the header row.|
|
187
|
+
|
188
|
+
<br>
|
189
|
+
#### `SpreadsheetArchitect.to_xlsx`
|
190
|
+
|Option|Type|Default|Notes|
|
191
|
+
|---|---|---|---|
|
192
|
+
|**data**|Array| |**Required** 2D Array of data for the non-header row cells. |
|
193
|
+
|**headers**|Array|`false`|2D Array of data for the header rows cells. Pass false to skip the header row.|
|
194
|
+
|**sheet_name**|String|`SpreadsheetArchitect`||
|
195
|
+
|**header_style**|Hash|`{background_color: "AAAAAA", color: "FFFFFF", align: :center, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`||
|
196
|
+
|**row_style**|Hash|`{background_color: nil, color: "FFFFFF", align: :left, font_name: 'Arial', font_size: 10, bold: false, italic: false, underline: false}`|Styles for non-header rows.|
|
197
|
+
|
198
|
+
<br>
|
199
|
+
#### `SpreadsheetArchitect.to_ods`
|
200
|
+
|Option|Type|Default|Notes|
|
201
|
+
|---|---|---|---|
|
202
|
+
|**data**|Array| |**Required** 2D Array of data for the non-header row cells.|
|
203
|
+
|**headers**|Array|`false`|2D Array of data for the header rows cells. Pass false to skip the header row.|
|
204
|
+
|**sheet_name**|String|`SpreadsheetArchitect`||
|
205
|
+
|**header_style**|Hash|`{color: "000000", align: :center, font_size: 10, bold: true}`|Note: Currently only supports these options (values can be changed though)|
|
206
|
+
|**row_style**|Hash|`{color: "000000", align: :left, font_size: 10, bold: false}`|Styles for non-header rows. Currently only supports these options (values can be changed though)|
|
207
|
+
|
208
|
+
<br>
|
209
|
+
#### `SpreadsheetArchitect.to_csv`
|
210
|
+
|Option|Type|Default|Notes|
|
211
|
+
|---|---|---|---|
|
212
|
+
|**data**|Array| |**Required** 2D Array of data for the non-header row cells.|
|
213
|
+
|**headers**|Array|`false`|2D Array of data for the header rows cells. Pass false to skip the header row.|
|
156
214
|
|
157
|
-
### to_csv
|
158
|
-
Only the generic options
|
159
215
|
|
160
216
|
|
161
217
|
# Change model default method options
|
@@ -12,7 +12,13 @@ module SpreadsheetArchitect
|
|
12
12
|
|
13
13
|
class NoDataError < StandardError
|
14
14
|
def initialize
|
15
|
-
super("Missing data option or
|
15
|
+
super("Missing data option or data is empty")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class NoInstancesError < StandardError
|
20
|
+
def initialize
|
21
|
+
super("Missing instances option or relation is empty.")
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
@@ -47,95 +53,130 @@ module SpreadsheetArchitect
|
|
47
53
|
return type
|
48
54
|
end
|
49
55
|
|
50
|
-
def self.
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
56
|
+
def self.get_cell_data(options={}, klass)
|
57
|
+
if klass.name == 'SpreadsheetArchitect'
|
58
|
+
if !options[:data] || options[:data].empty?
|
59
|
+
raise SpreadsheetArchitect::NoDataError
|
60
|
+
end
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
if options[:headers] && !options[:headers].empty?
|
63
|
+
headers = options[:headers]
|
64
|
+
else
|
65
|
+
headers = false
|
66
|
+
end
|
67
|
+
|
68
|
+
data = options[:data]
|
60
69
|
|
61
|
-
if !has_custom_columns && defined?(ActiveRecord) && klass.ancestors.include?(ActiveRecord::Base)
|
62
|
-
ignored_columns = ["id","created_at","updated_at","deleted_at"]
|
63
|
-
the_column_names = (klass.column_names - ignored_columns)
|
64
|
-
headers = the_column_names.map{|x| str_humanize(x)}
|
65
|
-
columns = the_column_names.map{|x| x.to_sym}
|
66
|
-
types = klass.columns.keep_if{|x| !ignored_columns.include?(x.name)}.collect(&:type)
|
67
|
-
types.map!{|type| self.get_type(nil, type)}
|
68
|
-
elsif has_custom_columns
|
69
|
-
headers = []
|
70
|
-
columns = []
|
71
70
|
types = []
|
72
|
-
|
73
|
-
|
74
|
-
if x.is_a?(Array)
|
75
|
-
headers.push x[0].to_s
|
76
|
-
columns.push x[1]
|
77
|
-
#types.push self.get_type(x[1], x[2])
|
78
|
-
types.push self.get_type(x[1], nil)
|
79
|
-
else
|
80
|
-
headers.push str_humanize(x.to_s)
|
81
|
-
columns.push x
|
82
|
-
types.push self.get_type(x, nil)
|
83
|
-
end
|
71
|
+
data.first.each do |x|
|
72
|
+
types.push self.get_type(x, nil)
|
84
73
|
end
|
85
74
|
else
|
86
|
-
|
87
|
-
end
|
75
|
+
has_custom_columns = options[:spreadsheet_columns] || klass.instance_methods.include?(:spreadsheet_columns)
|
88
76
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
77
|
+
if !options[:instances] && defined?(ActiveRecord) && klass.ancestors.include?(ActiveRecord::Base)
|
78
|
+
options[:instances] = klass.where(options[:where]).order(options[:order]).to_a
|
79
|
+
end
|
80
|
+
|
81
|
+
if !options[:instances] || options[:instances].empty?
|
82
|
+
raise SpreadsheetArchitect::NoInstancesError
|
83
|
+
end
|
84
|
+
|
85
|
+
if has_custom_columns
|
86
|
+
headers = []
|
87
|
+
columns = []
|
88
|
+
types = []
|
89
|
+
array = options[:spreadsheet_columns] || options[:instances].first.spreadsheet_columns
|
90
|
+
array.each do |x|
|
94
91
|
if x.is_a?(Array)
|
95
|
-
|
92
|
+
headers.push x[0].to_s
|
93
|
+
columns.push x[1]
|
94
|
+
#types.push self.get_type(x[1], x[2])
|
95
|
+
types.push self.get_type(x[1], nil)
|
96
96
|
else
|
97
|
-
|
97
|
+
headers.push str_humanize(x.to_s)
|
98
|
+
columns.push x
|
99
|
+
types.push self.get_type(x, nil)
|
98
100
|
end
|
99
101
|
end
|
100
|
-
|
102
|
+
elsif !has_custom_columns && defined?(ActiveRecord) && klass.ancestors.include?(ActiveRecord::Base)
|
103
|
+
ignored_columns = ["id","created_at","updated_at","deleted_at"]
|
104
|
+
the_column_names = (klass.column_names - ignored_columns)
|
105
|
+
headers = the_column_names.map{|x| str_humanize(x)}
|
106
|
+
columns = the_column_names.map{|x| x.to_sym}
|
107
|
+
types = klass.columns.keep_if{|x| !ignored_columns.include?(x.name)}.collect(&:type)
|
108
|
+
types.map!{|type| self.get_type(nil, type)}
|
101
109
|
else
|
102
|
-
|
110
|
+
raise SpreadsheetArchitect::SpreadsheetColumnsNotDefined, klass
|
111
|
+
end
|
112
|
+
|
113
|
+
if options[:headers].nil?
|
114
|
+
options[:headers] = klass::SPREADSHEET_OPTIONS[:headers] if defined?(klass::SPREADSHEET_OPTIONS)
|
115
|
+
options[:headers] = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:headers] if options[:headers].nil?
|
116
|
+
end
|
117
|
+
if options[:headers].nil? || options[:headers] == false
|
118
|
+
headers = false
|
119
|
+
end
|
120
|
+
|
121
|
+
data = []
|
122
|
+
options[:instances].each do |instance|
|
123
|
+
if has_custom_columns && !options[:spreadsheet_columns]
|
124
|
+
row_data = []
|
125
|
+
instance.spreadsheet_columns.each do |x|
|
126
|
+
if x.is_a?(Array)
|
127
|
+
row_data.push(x[1].is_a?(Symbol) ? instance.instance_eval(x[1].to_s) : x[1])
|
128
|
+
else
|
129
|
+
row_data.push(x.is_a?(Symbol) ? instance.instance_eval(x.to_s) : x)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
data.push row_data
|
133
|
+
else
|
134
|
+
data.push columns.map{|col| col.is_a?(Symbol) ? instance.instance_eval(col.to_s) : col}
|
135
|
+
end
|
103
136
|
end
|
104
|
-
end
|
105
137
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
138
|
+
# Fixes missing types from symbol methods
|
139
|
+
if has_custom_columns || options[:spreadsheet_columns]
|
140
|
+
data.first.each_with_index do |x,i|
|
141
|
+
if types[i] == :symbol
|
142
|
+
types[i] = self.get_type(x, nil, true)
|
143
|
+
end
|
111
144
|
end
|
112
145
|
end
|
113
146
|
end
|
114
147
|
|
115
|
-
|
116
|
-
|
117
|
-
end
|
148
|
+
return options.merge(headers: headers, data: data, types: types)
|
149
|
+
end
|
118
150
|
|
119
|
-
|
120
|
-
|
151
|
+
def self.get_options(options={}, klass)
|
152
|
+
if options[:headers]
|
153
|
+
if defined?(klass::SPREADSHEET_OPTIONS)
|
154
|
+
header_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:header_style].merge(klass::SPREADSHEET_OPTIONS[:header_style] || {})
|
155
|
+
else
|
156
|
+
header_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:header_style]
|
157
|
+
end
|
158
|
+
|
159
|
+
if options[:header_style]
|
160
|
+
header_style.merge!(options[:header_style])
|
161
|
+
elsif options[:header_style] == false
|
162
|
+
header_style = false
|
163
|
+
end
|
121
164
|
else
|
122
|
-
header_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:header_style]
|
123
|
-
end
|
124
|
-
|
125
|
-
if options[:header_style]
|
126
|
-
header_style.merge!(options[:header_style])
|
127
|
-
elsif options[:header_style] == false
|
128
165
|
header_style = false
|
129
166
|
end
|
130
167
|
|
131
|
-
if
|
132
|
-
row_style =
|
168
|
+
if options[:row_style] == false
|
169
|
+
row_style = false
|
133
170
|
else
|
134
|
-
|
135
|
-
|
171
|
+
if defined?(klass::SPREADSHEET_OPTIONS)
|
172
|
+
row_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:row_style].merge(klass::SPREADSHEET_OPTIONS[:row_style] || {})
|
173
|
+
else
|
174
|
+
row_style = SpreadsheetArchitect::SPREADSHEET_OPTIONS[:row_style]
|
175
|
+
end
|
136
176
|
|
137
|
-
|
138
|
-
|
177
|
+
if options[:row_style]
|
178
|
+
row_style.merge!(options[:row_style])
|
179
|
+
end
|
139
180
|
end
|
140
181
|
|
141
182
|
if defined?(klass::SPREADSHEET_OPTIONS)
|
@@ -144,12 +185,13 @@ module SpreadsheetArchitect
|
|
144
185
|
sheet_name = options[:sheet_name] || SpreadsheetArchitect::SPREADSHEET_OPTIONS[:sheet_name] || klass.name
|
145
186
|
end
|
146
187
|
|
147
|
-
return {headers: headers, header_style: header_style, row_style: row_style, types: types, sheet_name: sheet_name, data: data}
|
188
|
+
return {headers: options[:headers], header_style: header_style, row_style: row_style, types: options[:types], sheet_name: sheet_name, data: options[:data]}
|
148
189
|
end
|
149
190
|
end
|
150
191
|
|
151
192
|
module ClassMethods
|
152
193
|
def to_csv(opts={})
|
194
|
+
opts = SpreadsheetArchitect::Helpers.get_cell_data(opts, self)
|
153
195
|
options = SpreadsheetArchitect::Helpers.get_options(opts, self)
|
154
196
|
|
155
197
|
CSV.generate do |csv|
|
@@ -162,6 +204,7 @@ module SpreadsheetArchitect
|
|
162
204
|
end
|
163
205
|
|
164
206
|
def to_ods(opts={})
|
207
|
+
opts = SpreadsheetArchitect::Helpers.get_cell_data(opts, self)
|
165
208
|
options = SpreadsheetArchitect::Helpers.get_options(opts, self)
|
166
209
|
|
167
210
|
spreadsheet = ODF::Spreadsheet.new
|
@@ -220,37 +263,42 @@ module SpreadsheetArchitect
|
|
220
263
|
end
|
221
264
|
|
222
265
|
def to_xlsx(opts={})
|
266
|
+
opts = SpreadsheetArchitect::Helpers.get_cell_data(opts, self)
|
223
267
|
options = SpreadsheetArchitect::Helpers.get_options(opts, self)
|
224
268
|
|
225
269
|
header_style = {}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
header_style[:
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
270
|
+
if options[:header_style]
|
271
|
+
header_style[:fg_color] = options[:header_style].delete(:color)
|
272
|
+
header_style[:bg_color] = options[:header_style].delete(:background_color)
|
273
|
+
if header_style[:align]
|
274
|
+
header_style[:alignment] = {}
|
275
|
+
header_style[:alignment][:horizontal] = options[:header_style].delete(:align)
|
276
|
+
end
|
277
|
+
header_style[:b] = options[:header_style].delete(:bold)
|
278
|
+
header_style[:sz] = options[:header_style].delete(:font_size)
|
279
|
+
header_style[:i] = options[:header_style].delete(:italic)
|
280
|
+
if options[:header_style][:underline]
|
281
|
+
header_style[:u] = options[:header_style].delete(:underline)
|
282
|
+
end
|
283
|
+
header_style.delete_if{|x| x.nil?}
|
237
284
|
end
|
238
|
-
header_style.delete_if{|x| x.nil?}
|
239
285
|
|
240
286
|
row_style = {}
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
row_style[:
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
287
|
+
if options[:row_style]
|
288
|
+
row_style[:fg_color] = options[:row_style].delete(:color)
|
289
|
+
row_style[:bg_color] = options[:row_style].delete(:background_color)
|
290
|
+
if row_style[:align]
|
291
|
+
row_style[:alignment] = {}
|
292
|
+
row_style[:alignment][:horizontal] = options[:row_style][:align]
|
293
|
+
end
|
294
|
+
row_style[:b] = options[:row_style].delete(:bold)
|
295
|
+
row_style[:sz] = options[:row_style].delete(:font_size)
|
296
|
+
row_style[:i] = options[:row_style].delete(:italic)
|
297
|
+
if options[:row_style][:underline]
|
298
|
+
row_style[:u] = options[:row_style].delete(:underline)
|
299
|
+
end
|
300
|
+
row_style.delete_if{|x| x.nil?}
|
252
301
|
end
|
253
|
-
row_style.delete_if{|x| x.nil?}
|
254
302
|
|
255
303
|
package = Axlsx::Package.new
|
256
304
|
|
@@ -270,6 +318,8 @@ module SpreadsheetArchitect
|
|
270
318
|
end
|
271
319
|
end
|
272
320
|
|
321
|
+
extend SpreadsheetArchitect::ClassMethods
|
322
|
+
|
273
323
|
SPREADSHEET_OPTIONS = {
|
274
324
|
headers: true,
|
275
325
|
#sheet_name: self.name,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spreadsheet_architect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Weston Ganger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: axlsx
|