spreadsheet 1.3.3 → 1.3.5

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/bin/irb +29 -0
  3. data/bin/racc +29 -0
  4. data/bin/rdbg +29 -0
  5. data/bin/rdoc +29 -0
  6. data/bin/ri +29 -0
  7. data/bin/rubocop +29 -0
  8. data/bin/ruby-parse +29 -0
  9. data/bin/ruby-rewrite +29 -0
  10. data/bin/standardrb +29 -0
  11. data/bin/test-unit +29 -0
  12. data/lib/parseexcel/parseexcel.rb +66 -58
  13. data/lib/parseexcel/parser.rb +1 -1
  14. data/lib/parseexcel.rb +1 -1
  15. data/lib/spreadsheet/column.rb +13 -10
  16. data/lib/spreadsheet/compatibility.rb +3 -1
  17. data/lib/spreadsheet/datatypes.rb +150 -147
  18. data/lib/spreadsheet/encodings.rb +20 -16
  19. data/lib/spreadsheet/errors.rb +2 -2
  20. data/lib/spreadsheet/excel/error.rb +23 -22
  21. data/lib/spreadsheet/excel/internals/biff5.rb +11 -11
  22. data/lib/spreadsheet/excel/internals/biff8.rb +13 -13
  23. data/lib/spreadsheet/excel/internals.rb +451 -451
  24. data/lib/spreadsheet/excel/offset.rb +34 -31
  25. data/lib/spreadsheet/excel/password_hash.rb +18 -18
  26. data/lib/spreadsheet/excel/reader/biff5.rb +34 -35
  27. data/lib/spreadsheet/excel/reader/biff8.rb +235 -222
  28. data/lib/spreadsheet/excel/reader.rb +1331 -1274
  29. data/lib/spreadsheet/excel/rgb.rb +91 -91
  30. data/lib/spreadsheet/excel/row.rb +99 -91
  31. data/lib/spreadsheet/excel/sst_entry.rb +41 -38
  32. data/lib/spreadsheet/excel/workbook.rb +87 -76
  33. data/lib/spreadsheet/excel/worksheet.rb +126 -107
  34. data/lib/spreadsheet/excel/writer/biff8.rb +57 -55
  35. data/lib/spreadsheet/excel/writer/format.rb +274 -256
  36. data/lib/spreadsheet/excel/writer/n_worksheet.rb +838 -798
  37. data/lib/spreadsheet/excel/writer/workbook.rb +672 -635
  38. data/lib/spreadsheet/excel/writer/worksheet.rb +899 -861
  39. data/lib/spreadsheet/excel/writer.rb +1 -1
  40. data/lib/spreadsheet/excel.rb +19 -12
  41. data/lib/spreadsheet/font.rb +31 -26
  42. data/lib/spreadsheet/format.rb +75 -59
  43. data/lib/spreadsheet/link.rb +8 -5
  44. data/lib/spreadsheet/note.rb +7 -6
  45. data/lib/spreadsheet/noteObject.rb +6 -5
  46. data/lib/spreadsheet/row.rb +35 -24
  47. data/lib/spreadsheet/version.rb +1 -1
  48. data/lib/spreadsheet/workbook.rb +28 -13
  49. data/lib/spreadsheet/worksheet.rb +103 -68
  50. data/lib/spreadsheet/writer.rb +3 -0
  51. data/lib/spreadsheet.rb +12 -15
  52. data/test/data/test_row_record_empty_range.xls +0 -0
  53. data/test/excel/reader.rb +8 -8
  54. data/test/excel/row.rb +35 -31
  55. data/test/excel/writer/workbook.rb +18 -16
  56. data/test/excel/writer/worksheet.rb +10 -8
  57. data/test/font.rb +44 -32
  58. data/test/format.rb +38 -33
  59. data/test/integration.rb +641 -598
  60. data/test/row.rb +5 -3
  61. data/test/suite.rb +7 -7
  62. data/test/workbook.rb +15 -14
  63. data/test/workbook_protection.rb +5 -5
  64. data/test/worksheet.rb +36 -34
  65. metadata +59 -6
@@ -1,4 +1,4 @@
1
- require 'spreadsheet/compatibility'
1
+ require "spreadsheet/compatibility"
2
2
 
3
3
  module Spreadsheet
4
4
  ##
@@ -6,155 +6,158 @@ module Spreadsheet
6
6
  # attributes (boolean, colors and enumerations)
7
7
  module Datatypes
8
8
  include Compatibility
9
- def Datatypes.append_features mod
9
+
10
+ def self.append_features mod
10
11
  super
11
12
  mod.module_eval do
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
- # Define instance methods to read and write color attributes.
100
- # For valid colors see COLORS
101
- def colors *args
102
- args.each do |key|
103
- attr_reader key
104
- define_method "#{key}=" do |name|
105
- name = name.to_s.downcase.to_sym
106
- if COLORS.include?(name)
107
- instance_variable_set ivar_name(key), name
108
- else
109
- raise ArgumentError, "unknown color '#{name}'"
110
- end
111
- end
112
- end
113
- end
114
- ##
115
- # Define instance methods to read and write enumeration attributes.
116
- # * The first argument designates the attribute name.
117
- # * The second argument designates the default value.
118
- # * All subsequent attributes are possible values.
119
- # * If the last attribute is a Hash, each value in the Hash designates
120
- # aliases for the corresponding key.
121
- def enum key, *values
122
- aliases = {}
123
- if values.last.is_a? Hash
124
- values.pop.each do |value, synonyms|
125
- if synonyms.is_a? Array
126
- synonyms.each do |synonym| aliases.store synonym, value end
127
- else
128
- aliases.store synonyms, value
129
- end
130
- end
131
- end
132
- values.each do |value|
133
- aliases.store value, value
134
- end
135
- define_method key do
136
- name = ivar_name key
137
- value = instance_variable_get(name) if instance_variables.include? name
138
- value || values.first
139
- end
140
- define_method "#{key}=" do |arg|
141
- if arg
142
- arg = aliases.fetch arg do
143
- aliases.fetch arg.to_s.downcase.gsub(/[ \-]/, '_').to_sym, arg
144
- end
145
- if values.any? do |val| val === arg end
146
- instance_variable_set(ivar_name(key), arg)
147
- else
148
- valid = values.collect do |val| val.inspect end.join ', '
149
- raise ArgumentError,
150
- "Invalid value '#{arg.inspect}' for #{key}. Valid values are: #{valid}"
13
+ class << self
14
+ ##
15
+ # Valid colors for color attributes.
16
+ COLORS = [:builtin_black, :builtin_white, :builtin_red, :builtin_green,
17
+ :builtin_blue, :builtin_yellow, :builtin_magenta, :builtin_cyan,
18
+ :text, :border, :pattern_bg, :dialog_bg, :chart_text, :chart_bg,
19
+ :chart_border, :tooltip_bg, :tooltip_text, :aqua,
20
+ :black, :blue, :cyan, :brown, :fuchsia, :gray, :grey, :green,
21
+ :lime, :magenta, :navy, :orange, :purple, :red, :silver, :white,
22
+ :yellow,
23
+ :xls_color_0,
24
+ :xls_color_1,
25
+ :xls_color_2,
26
+ :xls_color_3,
27
+ :xls_color_4,
28
+ :xls_color_5,
29
+ :xls_color_6,
30
+ :xls_color_7,
31
+ :xls_color_8,
32
+ :xls_color_9,
33
+ :xls_color_10,
34
+ :xls_color_11,
35
+ :xls_color_12,
36
+ :xls_color_13,
37
+ :xls_color_14,
38
+ :xls_color_15,
39
+ :xls_color_16,
40
+ :xls_color_17,
41
+ :xls_color_18,
42
+ :xls_color_19,
43
+ :xls_color_20,
44
+ :xls_color_21,
45
+ :xls_color_22,
46
+ :xls_color_23,
47
+ :xls_color_24,
48
+ :xls_color_25,
49
+ :xls_color_26,
50
+ :xls_color_27,
51
+ :xls_color_28,
52
+ :xls_color_29,
53
+ :xls_color_30,
54
+ :xls_color_31,
55
+ :xls_color_32,
56
+ :xls_color_33,
57
+ :xls_color_34,
58
+ :xls_color_35,
59
+ :xls_color_36,
60
+ :xls_color_37,
61
+ :xls_color_38,
62
+ :xls_color_39,
63
+ :xls_color_40,
64
+ :xls_color_41,
65
+ :xls_color_42,
66
+ :xls_color_43,
67
+ :xls_color_44,
68
+ :xls_color_45,
69
+ :xls_color_46,
70
+ :xls_color_47,
71
+ :xls_color_48,
72
+ :xls_color_49,
73
+ :xls_color_50,
74
+ :xls_color_51,
75
+ :xls_color_52,
76
+ :xls_color_53,
77
+ :xls_color_54,
78
+ :xls_color_55]
79
+ ##
80
+ # Define instance methods to read and write boolean attributes.
81
+ def boolean *args
82
+ args.each do |key|
83
+ define_method key do
84
+ name = ivar_name key
85
+ !!(instance_variable_get(name) if instance_variables.include?(name))
86
+ end
87
+ define_method :"#{key}?" do
88
+ send key
89
+ end
90
+ define_method :"#{key}=" do |arg|
91
+ arg = false if arg == 0
92
+ instance_variable_set(ivar_name(key), !!arg)
93
+ end
94
+ define_method :"#{key}!" do
95
+ send :"#{key}=", true
96
+ end
97
+ end
98
+ end
99
+
100
+ ##
101
+ # Define instance methods to read and write color attributes.
102
+ # For valid colors see COLORS
103
+ def colors *args
104
+ args.each do |key|
105
+ attr_reader key
106
+ define_method :"#{key}=" do |name|
107
+ name = name.to_s.downcase.to_sym
108
+ if COLORS.include?(name)
109
+ instance_variable_set ivar_name(key), name
110
+ else
111
+ raise ArgumentError, "unknown color '#{name}'"
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ ##
118
+ # Define instance methods to read and write enumeration attributes.
119
+ # * The first argument designates the attribute name.
120
+ # * The second argument designates the default value.
121
+ # * All subsequent attributes are possible values.
122
+ # * If the last attribute is a Hash, each value in the Hash designates
123
+ # aliases for the corresponding key.
124
+ def enum key, *values
125
+ aliases = {}
126
+ if values.last.is_a? Hash
127
+ values.pop.each do |value, synonyms|
128
+ if synonyms.is_a? Array
129
+ synonyms.each { |synonym| aliases.store synonym, value }
130
+ else
131
+ aliases.store synonyms, value
132
+ end
133
+ end
134
+ end
135
+ values.each do |value|
136
+ aliases.store value, value
137
+ end
138
+ define_method key do
139
+ name = ivar_name key
140
+ value = instance_variable_get(name) if instance_variables.include? name
141
+ value || values.first
142
+ end
143
+ define_method :"#{key}=" do |arg|
144
+ if arg
145
+ arg = aliases.fetch arg do
146
+ aliases.fetch arg.to_s.downcase.gsub(/[ -]/, "_").to_sym, arg
147
+ end
148
+ if values.any? { |val| val === arg }
149
+ instance_variable_set(ivar_name(key), arg)
150
+ else
151
+ valid = values.collect { |val| val.inspect }.join ", "
152
+ raise ArgumentError,
153
+ "Invalid value '#{arg.inspect}' for #{key}. Valid values are: #{valid}"
154
+ end
155
+ else
156
+ instance_variable_set ivar_name(key), values.first
157
+ end
158
+ end
159
+ end
151
160
  end
152
- else
153
- instance_variable_set ivar_name(key), values.first
154
- end
155
- end
156
- end
157
- end
158
161
  end
159
162
  end
160
163
  end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
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 >= '1.9'
11
- def client string, internal='UTF-16LE'
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
- def internal string, client=Spreadsheet.client_encoding
16
+
17
+ def internal string, client = Spreadsheet.client_encoding
17
18
  string = string.dup
18
19
  string.force_encoding client
19
- string.encode('UTF-16LE').force_encoding('ASCII-8BIT')
20
+ string.encode("UTF-16LE").force_encoding("ASCII-8BIT")
20
21
  end
21
- def utf8 string, client=Spreadsheet.client_encoding
22
+
23
+ def utf8 string, client = Spreadsheet.client_encoding
22
24
  string = string.dup
23
25
  string.force_encoding client
24
- string.encode('UTF-8')
26
+ string.encode("UTF-8")
25
27
  end
26
28
  else
27
- require 'iconv'
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='UTF-16LE'
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
- def internal string, client=Spreadsheet.client_encoding, to_encoding = 'UTF-16LE'
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
- def utf8 string, client=Spreadsheet.client_encoding, to_encoding = 'UTF-8'
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='UTF-16LE'
59
+ def client string, internal = "UTF-16LE"
56
60
  string.delete "\0"
57
61
  end
58
- def internal string, internal='UTF-16LE'
59
- string.split('').zip(Array.new(string.size, 0.chr)).join
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
-
@@ -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 = Class.new(StandardError)
4
+ BaseError = Class.new(StandardError)
5
5
 
6
6
  # A codepage not stored in Spreadsheet::Internals::CODEPAGES
7
- UnknownCodepage = Class.new(BaseError)
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
@@ -1,26 +1,27 @@
1
1
  module Spreadsheet
2
2
  module Excel
3
- ##
4
- # This class encapsulates Excel Error-Codes
5
- class Error
6
- attr_reader :code
7
- ERROR_VALUES = {
8
- 0x00 => '#NULL!', # Intersection of two cell ranges is empty
9
- 0x07 => '#DIV/0!', # Division by zero
10
- 0x0F => '#VALUE!', # Wrong type of operand
11
- 0x17 => '#REF!', # Illegal or deleted cell reference
12
- 0x1D => '#NAME?', # Wrong function or range name
13
- 0x24 => '#NUM!', # Value range overflow
14
- 0x2A => '#N/A!', # Argument or function not available
15
- }
16
- def initialize code
17
- @code = code
18
- end
19
- ##
20
- # The String value Excel associates with an Error code
21
- def value
22
- ERROR_VALUES.fetch @code, '#UNKNOWN'
23
- end
24
- end
3
+ ##
4
+ # This class encapsulates Excel Error-Codes
5
+ class Error
6
+ attr_reader :code
7
+ ERROR_VALUES = {
8
+ 0x00 => "#NULL!", # Intersection of two cell ranges is empty
9
+ 0x07 => "#DIV/0!", # Division by zero
10
+ 0x0F => "#VALUE!", # Wrong type of operand
11
+ 0x17 => "#REF!", # Illegal or deleted cell reference
12
+ 0x1D => "#NAME?", # Wrong function or range name
13
+ 0x24 => "#NUM!", # Value range overflow
14
+ 0x2A => "#N/A!" # Argument or function not available
15
+ }
16
+ def initialize code
17
+ @code = code
18
+ end
19
+
20
+ ##
21
+ # The String value Excel associates with an Error code
22
+ def value
23
+ ERROR_VALUES.fetch @code, "#UNKNOWN"
24
+ end
25
+ end
25
26
  end
26
27
  end
@@ -1,17 +1,17 @@
1
1
  module Spreadsheet
2
2
  module Excel
3
3
  module Internals
4
- ##
5
- # Binary Formats and other configurations internal to Biff5. This Module is
6
- # likely to be expanded as Support for older Versions of Excel grows.
7
- module Biff5
8
- BINARY_FORMATS = {
9
- :dimensions => 'v5',
10
- }
11
- def binfmt key # :nodoc:
12
- BINARY_FORMATS.fetch key do super end
13
- end
14
- end
4
+ ##
5
+ # Binary Formats and other configurations internal to Biff5. This Module is
6
+ # likely to be expanded as Support for older Versions of Excel grows.
7
+ module Biff5
8
+ BINARY_FORMATS = {
9
+ dimensions: "v5"
10
+ }
11
+ def binfmt key # :nodoc:
12
+ BINARY_FORMATS.fetch key do super end # standard:disable BlockSingleLineBraces
13
+ end
14
+ end
15
15
  end
16
16
  end
17
17
  end
@@ -1,19 +1,19 @@
1
1
  module Spreadsheet
2
2
  module Excel
3
3
  module Internals
4
- ##
5
- # Binary Formats and other configurations internal to Biff8. This Module is
6
- # likely to be expanded as Support for older Versions of Excel grows and more
7
- # Binary formats are moved here for disambiguation.
8
- module Biff8
9
- BINARY_FORMATS = {
10
- :bof => 'v4V2',
11
- :dimensions => 'V2v2x2',
12
- }
13
- def binfmt key # :nodoc:
14
- BINARY_FORMATS.fetch key do super end
15
- end
16
- end
4
+ ##
5
+ # Binary Formats and other configurations internal to Biff8. This Module is
6
+ # likely to be expanded as Support for older Versions of Excel grows and more
7
+ # Binary formats are moved here for disambiguation.
8
+ module Biff8
9
+ BINARY_FORMATS = {
10
+ bof: "v4V2",
11
+ dimensions: "V2v2x2"
12
+ }
13
+ def binfmt key # :nodoc:
14
+ BINARY_FORMATS.fetch key do super end # standard:disable BlockSingleLineBraces
15
+ end
16
+ end
17
17
  end
18
18
  end
19
19
  end