Skip to content

Instantly share code, notes, and snippets.

@rolfb
Last active December 10, 2015 18:28
Show Gist options
  • Save rolfb/4474337 to your computer and use it in GitHub Desktop.
Save rolfb/4474337 to your computer and use it in GitHub Desktop.
Example WriteExcel script with UTF-8 strings which doesn't work with jruby-1.7.2 Before running do "gem install writeexcel"
# encoding: utf-8
require 'writeexcel'
string_utf8 = "øæaaø"
string_no_utf8 = "abc"
excel = WriteExcel.new("out.xls")
ws = excel.add_worksheet
ws.write("A1", string_utf8)
ws.write("A2", string_no_utf8)
excel.close
# encoding: utf-8
require 'nkf'
utf8 = "aæøåbøøc"
utf16le = NKF.nkf('-w16L0 -m0 -W', utf8)
utf16le.force_encoding('UTF-16LE')
puts RUBY_DESCRIPTION
puts utf16le
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment