felixbuenemann / xlsxtream

Streaming & Fast XLSX Spreadsheet Writer for Ruby
MIT License
217 stars 38 forks source link

Encoding::UndefinedConversionError: "\xEF" from ASCII-8BIT to UTF-8 #40

Closed yathi closed 4 years ago

yathi commented 4 years ago

I am running into the following error when trying to use the gem. I suspect its because I am using data with wrong encoding. I am not sure how to solve it though and any ideas are welcome. My code looks like this:

Xlsxtream::Workbook.open(filename) do |xlsx|
      xlsx.write_worksheet WORKSHEET_NAME do |sheet|
        sheet << headings
      end
end

headings here is an array of values. Do the values have to be in a particular format?

I tried the example provided:

Xlsxtream::Workbook.open(filename) do |xlsx|
      xlsx.write_worksheet WORKSHEET_NAME do |sheet|
        # Boolean, Date, Time, DateTime and Numeric are properly mapped
        sheet << [true, Date.today, 'hello', 'world', 42, 3.14159265359, 42**13]
      end
end

and even this is giving me Encoding::UndefinedConversionError: "\x91" from ASCII-8BIT to UTF-8. The character is different. But the same error.

yathi commented 4 years ago

Found the issue. This happens if the filename already exists. If the filename was new, this works just fine.