mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-31 12:09:17 +08:00
Fix excel header parsing
This commit is contained in:
parent
313897c1f7
commit
3b08241b0b
1 changed files with 10 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue