diff --git a/lib/spreadsheet/encodings.rb b/lib/spreadsheet/encodings.rb index 07713b6..fd9ace3 100644 --- a/lib/spreadsheet/encodings.rb +++ b/lib/spreadsheet/encodings.rb @@ -1,17 +1,25 @@ +#!/usr/bin/env ruby +# encoding: utf-8 +# Spreadsheet::Encoding -- spreadheet -- 07.09.2011 -- mhatakeyama@ywesee.com +# Spreadsheet::Encoding -- spreadheet -- 03.07.2009 -- hwyss@ywesee.com + module Spreadsheet ## # Methods for Encoding-conversions. You should not need to use any of these. module Encodings if RUBY_VERSION >= '1.9' def client string, internal='UTF-16LE' + string = string.dup string.force_encoding internal string.encode Spreadsheet.client_encoding end def internal string, client=Spreadsheet.client_encoding + string = string.dup string.force_encoding client string.encode('UTF-16LE').force_encoding('ASCII-8BIT') end def utf8 string, client=Spreadsheet.client_encoding + string = string.dup string.force_encoding client string.encode('UTF-8') end @@ -19,16 +27,19 @@ module Spreadsheet require 'iconv' @@iconvs = {} def client string, internal='UTF-16LE' + string = string.dup key = [Spreadsheet.client_encoding, internal] iconv = @@iconvs[key] ||= Iconv.new(Spreadsheet.client_encoding, internal) iconv.iconv string end def internal string, client=Spreadsheet.client_encoding + string = string.dup key = ['UTF-16LE', client] iconv = @@iconvs[key] ||= Iconv.new('UTF-16LE', client) iconv.iconv string end def utf8 string, client=Spreadsheet.client_encoding + string = string.dup key = ['UTF-8', client] iconv = @@iconvs[key] ||= Iconv.new('UTF-8', client) iconv.iconv string diff --git a/test/integration.rb b/test/integration.rb index ba9e0e2..8b691b1 100644 --- a/test/integration.rb +++ b/test/integration.rb @@ -1,6 +1,7 @@ #!/usr/bin/env ruby # encoding: utf-8 -# TestIntegration -- Spreadheet -- 08.10.2007 -- hwyss@ywesee.com +# TestIntegration -- spreadheet -- 07.09.2011 -- mhatakeyama@ywesee.com +# TestIntegration -- spreadheet -- 08.10.2007 -- hwyss@ywesee.com $: << File.expand_path('../lib', File.dirname(__FILE__)) @@ -1294,6 +1295,17 @@ module Spreadsheet end end =end + def test_write_frozen_string + Spreadsheet.client_encoding = 'UTF-16LE' + book = Spreadsheet::Workbook.new + path = File.join @var, 'test_write_workbook.xls' + sheet1 = book.create_worksheet + str1 = "Frozen String.".freeze + sheet1[0,0] = str1 + sheet1.row(0).push str1 + assert_nothing_raised do + book.write path + end + end end end -