spreadsheet 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/parseexcel/parseexcel.rb +66 -58
- data/lib/parseexcel/parser.rb +1 -1
- data/lib/parseexcel.rb +1 -1
- data/lib/spreadsheet/column.rb +11 -9
- data/lib/spreadsheet/compatibility.rb +3 -1
- data/lib/spreadsheet/datatypes.rb +149 -147
- data/lib/spreadsheet/encodings.rb +20 -16
- data/lib/spreadsheet/errors.rb +2 -2
- data/lib/spreadsheet/excel/error.rb +23 -22
- data/lib/spreadsheet/excel/internals/biff5.rb +11 -11
- data/lib/spreadsheet/excel/internals/biff8.rb +13 -13
- data/lib/spreadsheet/excel/internals.rb +451 -451
- data/lib/spreadsheet/excel/offset.rb +32 -31
- data/lib/spreadsheet/excel/password_hash.rb +18 -18
- data/lib/spreadsheet/excel/reader/biff5.rb +34 -35
- data/lib/spreadsheet/excel/reader/biff8.rb +234 -222
- data/lib/spreadsheet/excel/reader.rb +1320 -1274
- data/lib/spreadsheet/excel/rgb.rb +91 -91
- data/lib/spreadsheet/excel/row.rb +99 -91
- data/lib/spreadsheet/excel/sst_entry.rb +40 -38
- data/lib/spreadsheet/excel/workbook.rb +86 -76
- data/lib/spreadsheet/excel/worksheet.rb +125 -107
- data/lib/spreadsheet/excel/writer/biff8.rb +56 -55
- data/lib/spreadsheet/excel/writer/format.rb +273 -256
- data/lib/spreadsheet/excel/writer/n_worksheet.rb +837 -798
- data/lib/spreadsheet/excel/writer/workbook.rb +671 -635
- data/lib/spreadsheet/excel/writer/worksheet.rb +898 -861
- data/lib/spreadsheet/excel/writer.rb +1 -1
- data/lib/spreadsheet/excel.rb +18 -11
- data/lib/spreadsheet/font.rb +30 -26
- data/lib/spreadsheet/format.rb +74 -59
- data/lib/spreadsheet/link.rb +7 -5
- data/lib/spreadsheet/note.rb +6 -6
- data/lib/spreadsheet/noteObject.rb +5 -5
- data/lib/spreadsheet/row.rb +33 -23
- data/lib/spreadsheet/version.rb +1 -1
- data/lib/spreadsheet/workbook.rb +27 -13
- data/lib/spreadsheet/worksheet.rb +102 -68
- data/lib/spreadsheet/writer.rb +3 -0
- data/lib/spreadsheet.rb +12 -15
- data/test/excel/reader.rb +8 -8
- data/test/excel/row.rb +35 -31
- data/test/excel/writer/workbook.rb +18 -16
- data/test/excel/writer/worksheet.rb +10 -8
- data/test/font.rb +44 -32
- data/test/format.rb +38 -33
- data/test/integration.rb +627 -598
- data/test/row.rb +5 -3
- data/test/suite.rb +7 -7
- data/test/workbook.rb +15 -14
- data/test/workbook_protection.rb +5 -5
- data/test/worksheet.rb +36 -34
- metadata +48 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 992768cae61da12d700181640e3968fd5e10110bc04d0cc575820b0f63d6030e
|
4
|
+
data.tar.gz: 682b9a07e067b830c9f78889c15f8c8d70c0f94caa2e91d5e5743beed731cb01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aad8b496a030e98f5e7493c98f80ae090f15a7b2f80925217d189ec045fdd0bb61881bd8780c913a21e4eb3c481a477119d7a639a2253bc7ca918f5c48bee21e
|
7
|
+
data.tar.gz: 96c1b47b1cb6bafdc0afd57e10e84df7d2aaf2eb5859f1557ffedfee135450d009db1f3805cf3c0fbf7c7bd2c1a1e2ab91cfc15b5af5e3445d315faa889ae5aa
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spreadsheet"
|
2
2
|
|
3
|
-
warn
|
4
|
-
[DEPRECATED] By requiring 'parseexcel', 'parseexcel/parseexcel' and/or
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
warn <<~EOS
|
4
|
+
[DEPRECATED] By requiring 'parseexcel', 'parseexcel/parseexcel' and/or
|
5
|
+
'parseexcel/parser' you are loading a Compatibility layer which
|
6
|
+
provides a drop-in replacement for the ParseExcel library. This
|
7
|
+
code makes the reading of Spreadsheet documents less efficient and
|
8
|
+
will be removed in Spreadsheet version 1.0.0
|
9
9
|
EOS
|
10
10
|
|
11
11
|
module Spreadsheet
|
@@ -14,62 +14,70 @@ module Spreadsheet
|
|
14
14
|
# ParseExcel library. This code is deprecated and will be removed in
|
15
15
|
# Spreadsheet version 1.0.0
|
16
16
|
module ParseExcel
|
17
|
-
def
|
18
|
-
|
19
|
-
end
|
20
|
-
class Worksheet
|
21
|
-
class Cell
|
22
|
-
attr_accessor :value, :kind, :numeric, :code, :book,
|
23
|
-
:format, :rich, :encoding, :annotation
|
24
|
-
def initialize value, format, row, idx
|
25
|
-
@format = format
|
26
|
-
@idx = idx
|
27
|
-
@row = row
|
28
|
-
@value = value
|
29
|
-
@encoding = Spreadsheet.client_encoding
|
30
|
-
end
|
31
|
-
def date
|
32
|
-
@row.date @idx
|
33
|
-
end
|
34
|
-
def datetime
|
35
|
-
@row.datetime @idx
|
36
|
-
end
|
37
|
-
def to_i
|
38
|
-
@value.to_i
|
17
|
+
def self.parse path
|
18
|
+
Spreadsheet.open path
|
39
19
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
20
|
+
|
21
|
+
class Worksheet
|
22
|
+
class Cell
|
23
|
+
attr_accessor :value, :kind, :numeric, :code, :book,
|
24
|
+
:format, :rich, :encoding, :annotation
|
25
|
+
def initialize value, format, row, idx
|
26
|
+
@format = format
|
27
|
+
@idx = idx
|
28
|
+
@row = row
|
29
|
+
@value = value
|
30
|
+
@encoding = Spreadsheet.client_encoding
|
31
|
+
end
|
32
|
+
|
33
|
+
def date
|
34
|
+
@row.date @idx
|
35
|
+
end
|
36
|
+
|
37
|
+
def datetime
|
38
|
+
@row.datetime @idx
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_i
|
42
|
+
@value.to_i
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_f
|
46
|
+
@value.to_f
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s(target_encoding = nil)
|
50
|
+
if target_encoding
|
51
|
+
begin
|
52
|
+
Iconv.new(target_encoding, @encoding).iconv(@value)
|
53
|
+
rescue
|
54
|
+
Iconv.new(target_encoding, "ascii").iconv(@value.to_s)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
@value.to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def type
|
62
|
+
if @format && (@format.date? || @format.time?)
|
63
|
+
:date
|
64
|
+
elsif @value.is_a?(Numeric)
|
65
|
+
:numeric
|
66
|
+
else
|
67
|
+
:text
|
68
|
+
end
|
49
69
|
end
|
50
|
-
else
|
51
|
-
@value.to_s
|
52
|
-
end
|
53
|
-
end
|
54
|
-
def type
|
55
|
-
if @format && (@format.date? || @format.time?)
|
56
|
-
:date
|
57
|
-
elsif @value.is_a?(Numeric)
|
58
|
-
:numeric
|
59
|
-
else
|
60
|
-
:text
|
61
70
|
end
|
62
71
|
end
|
63
72
|
end
|
64
|
-
|
65
|
-
end
|
73
|
+
|
66
74
|
module Excel
|
67
|
-
class Reader # :nodoc: all
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
75
|
+
class Reader # :nodoc: all
|
76
|
+
def set_cell worksheet, row, column, xf, value = nil
|
77
|
+
cells = @current_row_block[row] ||= Row.new(nil, row)
|
78
|
+
cells.formats[column] = xf = @workbook.format(xf)
|
79
|
+
cells[column] = ParseExcel::Worksheet::Cell.new(value, xf, cells, column)
|
80
|
+
end
|
81
|
+
end
|
74
82
|
end
|
75
83
|
end
|
data/lib/parseexcel/parser.rb
CHANGED
data/lib/parseexcel.rb
CHANGED
data/lib/spreadsheet/column.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spreadsheet/datatypes"
|
2
2
|
|
3
3
|
module Spreadsheet
|
4
4
|
##
|
@@ -22,9 +22,9 @@ module Spreadsheet
|
|
22
22
|
keys.each do |key|
|
23
23
|
unless instance_methods.include? "unupdated_#{key}="
|
24
24
|
alias_method :"unupdated_#{key}=", :"#{key}="
|
25
|
-
define_method "#{key}=" do |value|
|
26
|
-
send "unupdated_#{key}=", value
|
27
|
-
@worksheet
|
25
|
+
define_method :"#{key}=" do |value|
|
26
|
+
send :"unupdated_#{key}=", value
|
27
|
+
@worksheet&.column_updated @idx, self
|
28
28
|
value
|
29
29
|
end
|
30
30
|
end
|
@@ -38,23 +38,24 @@ module Spreadsheet
|
|
38
38
|
boolean :hidden, :collapsed
|
39
39
|
enum :outline_level, 0, Integer
|
40
40
|
updater :collapsed, :hidden, :outline_level, :width
|
41
|
-
def initialize idx, format, opts={}
|
41
|
+
def initialize idx, format, opts = {}
|
42
42
|
@worksheet = nil
|
43
43
|
@idx = idx
|
44
44
|
opts[:width] ||= 10
|
45
45
|
opts.each do |key, value|
|
46
|
-
|
46
|
+
send :"#{key}=", value
|
47
47
|
end
|
48
48
|
self.default_format = format
|
49
49
|
end
|
50
|
+
|
50
51
|
##
|
51
52
|
# Set the default Format for Cells in this Column.
|
52
53
|
def default_format= format
|
53
|
-
@worksheet
|
54
|
+
@worksheet&.add_format format
|
54
55
|
@default_format = format
|
55
|
-
@worksheet
|
56
|
-
format
|
56
|
+
@worksheet&.column_updated @idx, self
|
57
57
|
end
|
58
|
+
|
58
59
|
##
|
59
60
|
# Iterate over all cells in this column.
|
60
61
|
def each
|
@@ -62,6 +63,7 @@ module Spreadsheet
|
|
62
63
|
yield row[idx]
|
63
64
|
end
|
64
65
|
end
|
66
|
+
|
65
67
|
def == other # :nodoc:
|
66
68
|
other.is_a?(Column) && default_format == other.default_format \
|
67
69
|
&& width == other.width && hidden == other.hidden \
|
@@ -4,10 +4,11 @@ module Spreadsheet
|
|
4
4
|
# One of the most incisive changes in terms of meta-programming in Ruby 1.9
|
5
5
|
# is the switch from representing instance-variable names as Strings to
|
6
6
|
# presenting them as Symbols. ivar_name provides compatibility.
|
7
|
-
if RUBY_VERSION >=
|
7
|
+
if RUBY_VERSION >= "1.9"
|
8
8
|
def ivar_name symbol
|
9
9
|
:"@#{symbol}"
|
10
10
|
end
|
11
|
+
|
11
12
|
def method_name symbol
|
12
13
|
symbol.to_sym
|
13
14
|
end
|
@@ -15,6 +16,7 @@ module Spreadsheet
|
|
15
16
|
def ivar_name symbol
|
16
17
|
"@#{symbol}"
|
17
18
|
end
|
19
|
+
|
18
20
|
def method_name symbol
|
19
21
|
symbol.to_s
|
20
22
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "spreadsheet/compatibility"
|
2
2
|
|
3
3
|
module Spreadsheet
|
4
4
|
##
|
@@ -6,155 +6,157 @@ module Spreadsheet
|
|
6
6
|
# attributes (boolean, colors and enumerations)
|
7
7
|
module Datatypes
|
8
8
|
include Compatibility
|
9
|
-
def
|
9
|
+
def self.append_features mod
|
10
10
|
super
|
11
11
|
mod.module_eval do
|
12
|
-
class << self
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
12
|
+
class << self
|
13
|
+
##
|
14
|
+
# Valid colors for color attributes.
|
15
|
+
COLORS = [:builtin_black, :builtin_white, :builtin_red, :builtin_green,
|
16
|
+
:builtin_blue, :builtin_yellow, :builtin_magenta, :builtin_cyan,
|
17
|
+
:text, :border, :pattern_bg, :dialog_bg, :chart_text, :chart_bg,
|
18
|
+
:chart_border, :tooltip_bg, :tooltip_text, :aqua,
|
19
|
+
:black, :blue, :cyan, :brown, :fuchsia, :gray, :grey, :green,
|
20
|
+
:lime, :magenta, :navy, :orange, :purple, :red, :silver, :white,
|
21
|
+
:yellow,
|
22
|
+
:xls_color_0,
|
23
|
+
:xls_color_1,
|
24
|
+
:xls_color_2,
|
25
|
+
:xls_color_3,
|
26
|
+
:xls_color_4,
|
27
|
+
:xls_color_5,
|
28
|
+
:xls_color_6,
|
29
|
+
:xls_color_7,
|
30
|
+
:xls_color_8,
|
31
|
+
:xls_color_9,
|
32
|
+
:xls_color_10,
|
33
|
+
:xls_color_11,
|
34
|
+
:xls_color_12,
|
35
|
+
:xls_color_13,
|
36
|
+
:xls_color_14,
|
37
|
+
:xls_color_15,
|
38
|
+
:xls_color_16,
|
39
|
+
:xls_color_17,
|
40
|
+
:xls_color_18,
|
41
|
+
:xls_color_19,
|
42
|
+
:xls_color_20,
|
43
|
+
:xls_color_21,
|
44
|
+
:xls_color_22,
|
45
|
+
:xls_color_23,
|
46
|
+
:xls_color_24,
|
47
|
+
:xls_color_25,
|
48
|
+
:xls_color_26,
|
49
|
+
:xls_color_27,
|
50
|
+
:xls_color_28,
|
51
|
+
:xls_color_29,
|
52
|
+
:xls_color_30,
|
53
|
+
:xls_color_31,
|
54
|
+
:xls_color_32,
|
55
|
+
:xls_color_33,
|
56
|
+
:xls_color_34,
|
57
|
+
:xls_color_35,
|
58
|
+
:xls_color_36,
|
59
|
+
:xls_color_37,
|
60
|
+
:xls_color_38,
|
61
|
+
:xls_color_39,
|
62
|
+
:xls_color_40,
|
63
|
+
:xls_color_41,
|
64
|
+
:xls_color_42,
|
65
|
+
:xls_color_43,
|
66
|
+
:xls_color_44,
|
67
|
+
:xls_color_45,
|
68
|
+
:xls_color_46,
|
69
|
+
:xls_color_47,
|
70
|
+
:xls_color_48,
|
71
|
+
:xls_color_49,
|
72
|
+
:xls_color_50,
|
73
|
+
:xls_color_51,
|
74
|
+
:xls_color_52,
|
75
|
+
:xls_color_53,
|
76
|
+
:xls_color_54,
|
77
|
+
:xls_color_55]
|
78
|
+
##
|
79
|
+
# Define instance methods to read and write boolean attributes.
|
80
|
+
def boolean *args
|
81
|
+
args.each do |key|
|
82
|
+
define_method key do
|
83
|
+
name = ivar_name key
|
84
|
+
!!(instance_variable_get(name) if instance_variables.include?(name))
|
85
|
+
end
|
86
|
+
define_method :"#{key}?" do
|
87
|
+
send key
|
88
|
+
end
|
89
|
+
define_method :"#{key}=" do |arg|
|
90
|
+
arg = false if arg == 0
|
91
|
+
instance_variable_set(ivar_name(key), !!arg)
|
92
|
+
end
|
93
|
+
define_method :"#{key}!" do
|
94
|
+
send :"#{key}=", true
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Define instance methods to read and write color attributes.
|
101
|
+
# For valid colors see COLORS
|
102
|
+
def colors *args
|
103
|
+
args.each do |key|
|
104
|
+
attr_reader key
|
105
|
+
define_method :"#{key}=" do |name|
|
106
|
+
name = name.to_s.downcase.to_sym
|
107
|
+
if COLORS.include?(name)
|
108
|
+
instance_variable_set ivar_name(key), name
|
109
|
+
else
|
110
|
+
raise ArgumentError, "unknown color '#{name}'"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Define instance methods to read and write enumeration attributes.
|
118
|
+
# * The first argument designates the attribute name.
|
119
|
+
# * The second argument designates the default value.
|
120
|
+
# * All subsequent attributes are possible values.
|
121
|
+
# * If the last attribute is a Hash, each value in the Hash designates
|
122
|
+
# aliases for the corresponding key.
|
123
|
+
def enum key, *values
|
124
|
+
aliases = {}
|
125
|
+
if values.last.is_a? Hash
|
126
|
+
values.pop.each do |value, synonyms|
|
127
|
+
if synonyms.is_a? Array
|
128
|
+
synonyms.each { |synonym| aliases.store synonym, value }
|
129
|
+
else
|
130
|
+
aliases.store synonyms, value
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
values.each do |value|
|
135
|
+
aliases.store value, value
|
136
|
+
end
|
137
|
+
define_method key do
|
138
|
+
name = ivar_name key
|
139
|
+
value = instance_variable_get(name) if instance_variables.include? name
|
140
|
+
value || values.first
|
141
|
+
end
|
142
|
+
define_method :"#{key}=" do |arg|
|
143
|
+
if arg
|
144
|
+
arg = aliases.fetch arg do
|
145
|
+
aliases.fetch arg.to_s.downcase.gsub(/[ \-]/, "_").to_sym, arg
|
146
|
+
end
|
147
|
+
if values.any? { |val| val === arg }
|
148
|
+
instance_variable_set(ivar_name(key), arg)
|
149
|
+
else
|
150
|
+
valid = values.collect { |val| val.inspect }.join ", "
|
151
|
+
raise ArgumentError,
|
152
|
+
"Invalid value '#{arg.inspect}' for #{key}. Valid values are: #{valid}"
|
153
|
+
end
|
154
|
+
else
|
155
|
+
instance_variable_set ivar_name(key), values.first
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
151
159
|
end
|
152
|
-
else
|
153
|
-
instance_variable_set ivar_name(key), values.first
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
160
|
end
|
159
161
|
end
|
160
162
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
3
|
# Spreadsheet::Encoding -- spreadheet -- 07.09.2011 -- mhatakeyama@ywesee.com
|
4
4
|
# Spreadsheet::Encoding -- spreadheet -- 03.07.2009 -- hwyss@ywesee.com
|
5
5
|
|
@@ -7,43 +7,47 @@ module Spreadsheet
|
|
7
7
|
##
|
8
8
|
# Methods for Encoding-conversions. You should not need to use any of these.
|
9
9
|
module Encodings
|
10
|
-
if RUBY_VERSION >=
|
11
|
-
def client string, internal=
|
10
|
+
if RUBY_VERSION >= "1.9"
|
11
|
+
def client string, internal = "UTF-16LE"
|
12
12
|
string = string.dup
|
13
13
|
string.force_encoding internal
|
14
14
|
string.encode Spreadsheet.client_encoding
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
|
+
def internal string, client = Spreadsheet.client_encoding
|
17
18
|
string = string.dup
|
18
19
|
string.force_encoding client
|
19
|
-
string.encode(
|
20
|
+
string.encode("UTF-16LE").force_encoding("ASCII-8BIT")
|
20
21
|
end
|
21
|
-
|
22
|
+
|
23
|
+
def utf8 string, client = Spreadsheet.client_encoding
|
22
24
|
string = string.dup
|
23
25
|
string.force_encoding client
|
24
|
-
string.encode(
|
26
|
+
string.encode("UTF-8")
|
25
27
|
end
|
26
28
|
else
|
27
|
-
require
|
29
|
+
require "iconv"
|
28
30
|
@@iconvs = {}
|
29
31
|
|
30
32
|
def build_output_encoding(to_encoding)
|
31
|
-
[to_encoding, Spreadsheet.enc_translit, Spreadsheet.enc_ignore].compact.join(
|
33
|
+
[to_encoding, Spreadsheet.enc_translit, Spreadsheet.enc_ignore].compact.join("//")
|
32
34
|
end
|
33
35
|
|
34
|
-
def client string, internal=
|
36
|
+
def client string, internal = "UTF-16LE"
|
35
37
|
string = string.dup
|
36
38
|
key = [Spreadsheet.client_encoding, internal]
|
37
39
|
iconv = @@iconvs[key] ||= Iconv.new(Spreadsheet.client_encoding, internal)
|
38
40
|
iconv.iconv string
|
39
41
|
end
|
40
|
-
|
42
|
+
|
43
|
+
def internal string, client = Spreadsheet.client_encoding, to_encoding = "UTF-16LE"
|
41
44
|
string = string.dup
|
42
45
|
key = [to_encoding, client]
|
43
46
|
iconv = @@iconvs[key] ||= Iconv.new(build_output_encoding(to_encoding), client)
|
44
47
|
iconv.iconv string
|
45
48
|
end
|
46
|
-
|
49
|
+
|
50
|
+
def utf8 string, client = Spreadsheet.client_encoding, to_encoding = "UTF-8"
|
47
51
|
string = string.dup
|
48
52
|
key = [to_encoding, client]
|
49
53
|
iconv = @@iconvs[key] ||= Iconv.new(build_output_encoding(to_encoding), client)
|
@@ -52,12 +56,12 @@ module Spreadsheet
|
|
52
56
|
end
|
53
57
|
rescue LoadError
|
54
58
|
warn "You don't have Iconv support compiled in your Ruby. Spreadsheet may not work as expected"
|
55
|
-
def client string, internal=
|
59
|
+
def client string, internal = "UTF-16LE"
|
56
60
|
string.delete "\0"
|
57
61
|
end
|
58
|
-
|
59
|
-
|
62
|
+
|
63
|
+
def internal string, internal = "UTF-16LE"
|
64
|
+
string.chars.zip(Array.new(string.size, 0.chr)).join
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|
63
|
-
|
data/lib/spreadsheet/errors.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Spreadsheet
|
2
2
|
# Custom errors raised by this gem, not errors from Excel
|
3
3
|
module Errors
|
4
|
-
BaseError
|
4
|
+
BaseError = Class.new(StandardError)
|
5
5
|
|
6
6
|
# A codepage not stored in Spreadsheet::Internals::CODEPAGES
|
7
|
-
UnknownCodepage
|
7
|
+
UnknownCodepage = Class.new(BaseError)
|
8
8
|
# The encoding can be known, but not supported by Ruby
|
9
9
|
UnsupportedEncoding = Class.new(BaseError)
|
10
10
|
end
|