62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/activerecord_to_google_spreadsheet/converter.rb', line 62
def to_google_spreadsheet(session, spreadsheet_key, name, worksheet_title: false, row_offset: 1)
if self.length > 0
spreadsheet = session.spreadsheet_by_key(spreadsheet_key)
ws = get_worksheet_by_name(spreadsheet, name)
self.each_with_index do |item, index|
if index == 0 && item.is_a?(ActiveRecord::Base) && worksheet_title
item.to_google_spreadsheet(session, spreadsheet_key, name: name, worksheet_title: true, row_offset: row_offset + index)
row_offset += 1
elsif item.is_a? ActiveRecord::Base
item.to_google_spreadsheet(session, spreadsheet_key, name: name, row_offset: row_offset + index)
elsif item.is_a? Array
item.each_with_index do |array_item, array_index|
ws[index + row_offset, array_index + 1] = item[name] = array_item
end
else
ws[index + row_offset, 1] = val
end
end
end
end
|