4

I am trying to use the roo gem to run some operations on an excel File. This works perfectly when I do it manually:

file = File.join(Rails.root, 'october_data.xlsx')
spreadsheet = Roo::Excelx.new(file)

However, this does not work when I upload the file via a form:

file = File.read params["Team Changes"]["document"].path
spreadsheet = Roo::Excelx.new(file)

I get the following error:

 ArgumentError (string contains null byte)

There seems to be a lot written about string contains null byte but nothing I've seen seems relevant to what I'm working on. How do I fix this?

Qwertie
  • 5,784
  • 12
  • 45
  • 89
Philip7899
  • 4,599
  • 4
  • 55
  • 114

1 Answers1

4

This happened to me. Apparently it is an encoding issue. Try specifying encoding to 'ASCII-8BIT' when you read the file.

file = File.read(params["Team Changes"]["document"].path, encoding: 'ASCII-8BIT')
spreadsheet = Roo::Excelx.new(file)