3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/xlsxtream_rails/utils.rb', line 3
def self.write_xls(xlsx, data)
= []
= true
needs_column_types = false
xlsx.write_worksheet(auto_format: false) do |sheet|
data.find_each do |instance, index|
row_data = []
instance_cols = instance.xlsx_columns
instance_cols.each_with_index do |x, i|
if x.is_a?(Array)
.push(i18n_attr(instance, x[0])) if
row_data.push(x[1].is_a?(Symbol) ? instance.send(x[1]) : x[1])
if needs_column_types
column_types[i] = x[2]
end
else
.push(i18n_attr(instance, x)) if
row_data.push(x.is_a?(Symbol) ? instance.send(x) : x)
end
end
sheet.add_row if
= false
sheet.add_row row_data
end
end
end
|