Fix excel header parsing

This commit is contained in:
Urban Rotnik 2020-05-18 09:52:37 +02:00
parent 313897c1f7
commit 3b08241b0b

View file

@ -39,20 +39,20 @@ class SpreadsheetParser
rows = spreadsheet_enumerator(sheet)
header = []
columns = []
i = 1
rows.each do |row_values|
# Creek XLSX parser returns Hash of the row, Roo - Array
row = parse_row(row_values, sheet)
header = row if i == 1 && row
columns = row if i == 2 && row
i += 1
break if i > 2
rows.take(2).each_with_index do |row_values, i|
row = parse_row(row_values, sheet, header: i.zero?)
if row && i.zero?
header = row
else
columns = row
end
end
return header, columns
end
def self.parse_row(row, sheet)
if sheet.is_a?(Roo::Excelx)
def self.parse_row(row, sheet, header: false)
if sheet.is_a?(Roo::Excelx) && !header
row.map do |cell|
if cell.is_a?(Roo::Excelx::Cell::Number) && cell.format == 'General'
cell&.value&.to_d