To convert Excel into CSV efficiently in ruby

I used the spreadsheet gem to do this. It works but it can be very slow
at times .I even tried the Roo gem, but that didn’t improve the
performance. Is there a better way to do this job? The weird thing is
that some worksheets in the same excel work faster and some worksheets
work very slowly, even taking up to 1 hour.

Can we use open office to open each worksheet(tab) in a single excel and
convert them to csv much faster? If yes, how would I do it in ruby?

Or is there an even better solution?

I use a mac and mostly run the code on unix/linux based machines so
using win2ole is not an option .

“faster” and “slowly” are rather subjective. Have you checked, for
example, whether you’re reading only the populated area or if you’re
including all the empty rows?
You ask for a better solution, but you haven’t provided any examples or
code.

Joel P. wrote in post #1146731:

“faster” and “slowly” are rather subjective. Have you checked, for
example, whether you’re reading only the populated area or if you’re
including all the empty rows?
You ask for a better solution, but you haven’t provided any examples or
code.

Spreadsheet.open source do |book|
  book.worksheets.each do |worksheet|
    csv.open File.join(destination, worksheet_name + ".csv"), "w+" 

do |csv|
worksheet.each do |row|
csv << [].tap do |csv_row|
row.each do |cell|
if cell.respond_to?(:value)
csv_row << cell.value
elsif cell.is_a?(Float)
csv_row << cell.to_s.gsub(/(.0+)\z/, “”)
else
csv_row << cell
end
end
end
end
end
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs