ntq_excelsior 1.2.2 → 1.3.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +21 -4
- data/lib/ntq_excelsior/exporter.rb +42 -2
- data/lib/ntq_excelsior/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a4efa937725b46c65a0ed4b23ebba4a10dc359835b6e7b563c2c7d7fa269404
|
4
|
+
data.tar.gz: a65826c126a6e9485dbb8227a439960a944ed4481138dca5bb2b5598db9d2490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d70936785c973e0d76ecb3d26ab0e676acfaa09c6c69e8bf7902a9b3c31608a8b81deef35ffb593ffbe0fbdeff76b04a9296ac757ccd7d5788a8c5059b4d7403
|
7
|
+
data.tar.gz: 5cb1daf2aef2b3829275277184af5bef789b73a33c2fc8e60ae5b4e4efc09db3f71591241ab6975417c2074d6cb82a622a33bd924b4742cb5b9f4b7400e567a9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,7 +34,7 @@ class UserExporter < NtqExcelsior::Exporter
|
|
34
34
|
[
|
35
35
|
{
|
36
36
|
title: "Utilisateurs",
|
37
|
-
width: -> (context) { context[:current_user].can?(:access_to_email, User) ? 4 : 3 }
|
37
|
+
width: -> (context) { context[:current_user].can?(:access_to_email, User) ? 4 : 3 },
|
38
38
|
# width: 4,
|
39
39
|
styles: [:bold]
|
40
40
|
}
|
@@ -69,7 +69,25 @@ class UserExporter < NtqExcelsior::Exporter
|
|
69
69
|
title: 'Age',
|
70
70
|
resolve: 'age',
|
71
71
|
type: :number
|
72
|
-
}
|
72
|
+
},
|
73
|
+
{
|
74
|
+
title: 'Civilité',
|
75
|
+
list: ['M', 'Ms', 'Autres']
|
76
|
+
},
|
77
|
+
{
|
78
|
+
title: 'Active',
|
79
|
+
resolve: -> (record) { record.active ? 'Oui' : 'Non' }
|
80
|
+
# See axlsx example [here](https://github.com/caxlsx/caxlsx/blob/master/examples/list_validation_example.md) for more options
|
81
|
+
list: {
|
82
|
+
options: ['Oui', 'Non'],
|
83
|
+
show_error_message: true,
|
84
|
+
error_title: 'Active', # Optional
|
85
|
+
error: 'Authorized value: Oui non',
|
86
|
+
errorStyle: :stop, # :informations, :warning
|
87
|
+
showInputMessage: true,
|
88
|
+
prompt: 'Choose a value'
|
89
|
+
}
|
90
|
+
},
|
73
91
|
]
|
74
92
|
})
|
75
93
|
|
@@ -96,8 +114,7 @@ send_data stream, type: 'application/xlsx', filename: "filename.xlsx"
|
|
96
114
|
user_exporter = UserExporter.new(@user_data)
|
97
115
|
product_exporter = ProductExporter.new(@product_data)
|
98
116
|
|
99
|
-
exporter = NtqExcelsior::MultiWorkbookExporter.new([
|
100
|
-
stream = exporter.export.to_stream.read
|
117
|
+
exporter = NtqExcelsior::MultiWorkbookExporter.new([export1, export2])
|
101
118
|
|
102
119
|
# In ruby file
|
103
120
|
File.open("export.xlsx", "w") do |tmp|
|
@@ -61,7 +61,7 @@ module NtqExcelsior
|
|
61
61
|
letters.reverse.map { |i| COLUMN_NAMES[i] }.join
|
62
62
|
end
|
63
63
|
|
64
|
-
def cell_name(col, row, *lock)
|
64
|
+
def cell_name(col, row = nil, *lock)
|
65
65
|
"#{lock.include?(:col) ? '$' : ''}#{column_name(col)}#{lock.include?(:row) ? '$' : ''}#{row}"
|
66
66
|
end
|
67
67
|
|
@@ -116,13 +116,19 @@ module NtqExcelsior
|
|
116
116
|
width = column_width(header)
|
117
117
|
row[:values] << header[:title] || ''
|
118
118
|
row[:styles] << get_styles(header[:header_styles] || header[:styles])
|
119
|
+
row[:data_validations] ||= []
|
120
|
+
if header[:list]
|
121
|
+
row[:data_validations].push({
|
122
|
+
range: cells_range([col_index, index + 1], [col_index, 1_000_000]),
|
123
|
+
config: list_data_validation_for_column(header[:list])
|
124
|
+
})
|
125
|
+
end
|
119
126
|
if width > 1
|
120
127
|
colspan = width - 1
|
121
128
|
row[:values].push(*Array.new(colspan, nil))
|
122
129
|
row[:merge_cells].push cells_range([col_index, index], [col_index + colspan, index])
|
123
130
|
col_index += colspan
|
124
131
|
end
|
125
|
-
|
126
132
|
col_index += 1
|
127
133
|
end
|
128
134
|
row
|
@@ -188,6 +194,35 @@ module NtqExcelsior
|
|
188
194
|
row
|
189
195
|
end
|
190
196
|
|
197
|
+
def list_data_validation_for_column(list_config)
|
198
|
+
if list_config.is_a?(Array)
|
199
|
+
return {
|
200
|
+
type: :list,
|
201
|
+
formula1: "\"#{list_config.join(', ')}\""
|
202
|
+
}
|
203
|
+
end
|
204
|
+
|
205
|
+
config = {
|
206
|
+
type: :list,
|
207
|
+
formula1: "\"#{list_config[:options].join(', ')}\"",
|
208
|
+
showErrorMessage: list_config[:show_error_message] || false,
|
209
|
+
showInputMessage: list_config[:show_input_message] || false,
|
210
|
+
}
|
211
|
+
|
212
|
+
if list_config[:show_error_message]
|
213
|
+
config[:error] = list_config[:error] || ''
|
214
|
+
config[:errorStyle] = list_config[:error_style] || :stop
|
215
|
+
config[:errorTitle] = list_config[:error_title] || ''
|
216
|
+
end
|
217
|
+
|
218
|
+
if list_config[:show_input_message]
|
219
|
+
config[:promptTitle] = list_config[:prompt_title] || ''
|
220
|
+
config[:prompt] = list_config[:prompt] || ''
|
221
|
+
end
|
222
|
+
|
223
|
+
config
|
224
|
+
end
|
225
|
+
|
191
226
|
def content
|
192
227
|
content = { rows: [] }
|
193
228
|
index = 0
|
@@ -213,6 +248,11 @@ module NtqExcelsior
|
|
213
248
|
end
|
214
249
|
end
|
215
250
|
sheet.add_row row[:values], style: row_style, height: row[:height], types: row[:types]
|
251
|
+
if row[:data_validations]
|
252
|
+
row[:data_validations].each do |validation|
|
253
|
+
sheet.add_data_validation(validation[:range], validation[:config])
|
254
|
+
end
|
255
|
+
end
|
216
256
|
if row[:merge_cells]
|
217
257
|
row[:merge_cells]&.each do |range|
|
218
258
|
sheet.merge_cells range
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntq_excelsior
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: caxlsx
|