weshatheleopard / rubyXL

Ruby lib for reading/writing/modifying .xlsx and .xlsm files
MIT License
1.27k stars 253 forks source link

Encoding::UndefinedConversionError: "\xAE" from ASCII-8BIT to UTF-8 #183

Open madtocode opened 9 years ago

madtocode commented 9 years ago

Getting the above error whenever I try to 'write' to an xlsx file. Modifying existing excel sheet raised this error. I even tried creating a new excel sheet as follows (in rails console):

[10] pry(main)> @result_workbook = RubyXL::Workbook.new
[11] pry(main)> @result_workbook.write("#{Rails.root}/public/uploads/test_output.xlsx")
Encoding::UndefinedConversionError: "\xAE" from ASCII-8BIT to UTF-8
from /Users/stk/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/fileutils.rb:488:in `write'

Just created a new workbook and saved it without performing any other operations, still it is failing.

Your help is appreciated.

madtocode commented 9 years ago

Any update on this please? I'm blocked right now.

weshatheleopard commented 9 years ago

@madtocode: ever heard about the tradition of providing the sample file, so the developer could, like, reproduce your problem?

madtocode commented 9 years ago

No need of file. I was getting the same problem when trying to create a new workbook using rubyXL. Just refer to the rails console commands given. I was creating a new workbook and saving with a name. That's it.

weshatheleopard commented 9 years ago

@madtocode: works just fine.

2.1.1 :001 > require 'rubyXL'
 => true
2.1.1 :002 > @result_workbook = RubyXL::Workbook.new
 => #<RubyXL::Workbook:0x000000029e2a08 ....... >
2.1.1 :003 > @result_workbook.write("test_output.xlsx")
 => "test_output.xlsx"
2.1.1 :004 > RUBY_VERSION
 => "2.1.1"
madtocode commented 9 years ago

I tried on Mac and centos, not working. On ubuntu, it worked. Is there any configuration need to done for this?

adding # encoding: utf-8 didn't work. Tried other things too. Could you please tell me where it actually is dependent on?

RUBY_VERSION we are using is 2.0.0

weshatheleopard commented 9 years ago

I'm on ubuntu.

I can't tell for sure what causes your problem, but I have a suspicion.

I suggest you do the following: in the console, execute the following code:

module RubyXL
  class Theme < OOXMLTopLevelObject
    def self.default
      default_theme = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme">
</a:theme>'

      self.parse(default_theme)
    end
  end
end

and then try again. See if it fixes things. If yes, I'll see what can be done.

madtocode commented 9 years ago

It's still the same @weshatheleopard even after executing the code block you provided. I'm using rubyXL version 3.1.0 btw.

weshatheleopard commented 9 years ago

Try adding # encoding: utf-8 to objects/theme.rb