nulogy-spreadsheet 0.6.5.7.2

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 (66) hide show
  1. data/.gitignore +3 -0
  2. data/GUIDE.txt +267 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +18 -0
  5. data/History.txt +365 -0
  6. data/LICENSE.txt +619 -0
  7. data/Manifest.txt +62 -0
  8. data/README.txt +107 -0
  9. data/Rakefile +1 -0
  10. data/bin/xlsopcodes +18 -0
  11. data/lib/parseexcel.rb +27 -0
  12. data/lib/parseexcel/parseexcel.rb +75 -0
  13. data/lib/parseexcel/parser.rb +11 -0
  14. data/lib/spreadsheet.rb +79 -0
  15. data/lib/spreadsheet/column.rb +71 -0
  16. data/lib/spreadsheet/compatibility.rb +23 -0
  17. data/lib/spreadsheet/datatypes.rb +105 -0
  18. data/lib/spreadsheet/encodings.rb +57 -0
  19. data/lib/spreadsheet/excel.rb +88 -0
  20. data/lib/spreadsheet/excel/error.rb +26 -0
  21. data/lib/spreadsheet/excel/internals.rb +361 -0
  22. data/lib/spreadsheet/excel/internals/biff5.rb +17 -0
  23. data/lib/spreadsheet/excel/internals/biff8.rb +19 -0
  24. data/lib/spreadsheet/excel/offset.rb +41 -0
  25. data/lib/spreadsheet/excel/reader.rb +1173 -0
  26. data/lib/spreadsheet/excel/reader/biff5.rb +22 -0
  27. data/lib/spreadsheet/excel/reader/biff8.rb +199 -0
  28. data/lib/spreadsheet/excel/row.rb +92 -0
  29. data/lib/spreadsheet/excel/sst_entry.rb +46 -0
  30. data/lib/spreadsheet/excel/workbook.rb +80 -0
  31. data/lib/spreadsheet/excel/worksheet.rb +100 -0
  32. data/lib/spreadsheet/excel/writer.rb +1 -0
  33. data/lib/spreadsheet/excel/writer/biff8.rb +75 -0
  34. data/lib/spreadsheet/excel/writer/format.rb +253 -0
  35. data/lib/spreadsheet/excel/writer/workbook.rb +653 -0
  36. data/lib/spreadsheet/excel/writer/worksheet.rb +886 -0
  37. data/lib/spreadsheet/font.rb +92 -0
  38. data/lib/spreadsheet/format.rb +177 -0
  39. data/lib/spreadsheet/formula.rb +9 -0
  40. data/lib/spreadsheet/helpers.rb +11 -0
  41. data/lib/spreadsheet/link.rb +43 -0
  42. data/lib/spreadsheet/row.rb +132 -0
  43. data/lib/spreadsheet/workbook.rb +126 -0
  44. data/lib/spreadsheet/worksheet.rb +277 -0
  45. data/lib/spreadsheet/writer.rb +30 -0
  46. data/nulogy-spreadsheet.gemspec +21 -0
  47. data/test/data/test_changes.xls +0 -0
  48. data/test/data/test_copy.xls +0 -0
  49. data/test/data/test_datetime.xls +0 -0
  50. data/test/data/test_empty.xls +0 -0
  51. data/test/data/test_formula.xls +0 -0
  52. data/test/data/test_long_sst_record.xls +0 -0
  53. data/test/data/test_missing_row.xls +0 -0
  54. data/test/data/test_version_excel5.xls +0 -0
  55. data/test/data/test_version_excel95.xls +0 -0
  56. data/test/data/test_version_excel97.xls +0 -0
  57. data/test/excel/row.rb +35 -0
  58. data/test/excel/writer/workbook.rb +23 -0
  59. data/test/excel/writer/worksheet.rb +55 -0
  60. data/test/font.rb +163 -0
  61. data/test/integration.rb +1311 -0
  62. data/test/row.rb +33 -0
  63. data/test/suite.rb +17 -0
  64. data/test/workbook.rb +29 -0
  65. data/test/worksheet.rb +80 -0
  66. metadata +162 -0
@@ -0,0 +1,23 @@
1
+ module Spreadsheet
2
+ module Compatibility
3
+ ##
4
+ # One of the most incisive changes in terms of meta-programming in Ruby 1.9
5
+ # is the switch from representing instance-variable names as Strings to
6
+ # presenting them as Symbols. ivar_name provides compatibility.
7
+ if RUBY_VERSION >= '1.9'
8
+ def ivar_name symbol
9
+ :"@#{symbol}"
10
+ end
11
+ def method_name symbol
12
+ symbol.to_sym
13
+ end
14
+ else
15
+ def ivar_name symbol
16
+ "@#{symbol}"
17
+ end
18
+ def method_name symbol
19
+ symbol.to_s
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,105 @@
1
+ require 'spreadsheet/compatibility'
2
+
3
+ module Spreadsheet
4
+ ##
5
+ # This module defines convenience-methods for the definition of Spreadsheet
6
+ # attributes (boolean, colors and enumerations)
7
+ module Datatypes
8
+ include Compatibility
9
+ def Datatypes.append_features mod
10
+ super
11
+ 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
+ ##
23
+ # Define instance methods to read and write boolean attributes.
24
+ def boolean *args
25
+ args.each do |key|
26
+ define_method key do
27
+ name = ivar_name key
28
+ !!(instance_variable_get(name) if instance_variables.include?(name))
29
+ end
30
+ define_method "#{key}?" do
31
+ send key
32
+ end
33
+ define_method "#{key}=" do |arg|
34
+ arg = false if arg == 0
35
+ instance_variable_set(ivar_name(key), !!arg)
36
+ end
37
+ define_method "#{key}!" do
38
+ send "#{key}=", true
39
+ end
40
+ end
41
+ end
42
+ ##
43
+ # Define instance methods to read and write color attributes.
44
+ # For valid colors see COLORS
45
+ def colors *args
46
+ args.each do |key|
47
+ attr_reader key
48
+ define_method "#{key}=" do |name|
49
+ name = name.to_s.downcase.to_sym
50
+ if COLORS.include?(name)
51
+ instance_variable_set ivar_name(key), name
52
+ else
53
+ raise ArgumentError, "unknown color '#{name}'"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ ##
59
+ # Define instance methods to read and write enumeration attributes.
60
+ # * The first argument designates the attribute name.
61
+ # * The second argument designates the default value.
62
+ # * All subsequent attributes are possible values.
63
+ # * If the last attribute is a Hash, each value in the Hash designates
64
+ # aliases for the corresponding key.
65
+ def enum key, *values
66
+ aliases = {}
67
+ if values.last.is_a? Hash
68
+ values.pop.each do |value, synonyms|
69
+ if synonyms.is_a? Array
70
+ synonyms.each do |synonym| aliases.store synonym, value end
71
+ else
72
+ aliases.store synonyms, value
73
+ end
74
+ end
75
+ end
76
+ values.each do |value|
77
+ aliases.store value, value
78
+ end
79
+ define_method key do
80
+ name = ivar_name key
81
+ value = instance_variable_get(name) if instance_variables.include? name
82
+ value || values.first
83
+ end
84
+ define_method "#{key}=" do |arg|
85
+ if arg
86
+ arg = aliases.fetch arg do
87
+ aliases.fetch arg.to_s.downcase.gsub(/[ \-]/, '_').to_sym, arg
88
+ end
89
+ if values.any? do |val| val === arg end
90
+ instance_variable_set(ivar_name(key), arg)
91
+ else
92
+ valid = values.collect do |val| val.inspect end.join ', '
93
+ raise ArgumentError,
94
+ "Invalid value '#{arg.inspect}' for #{key}. Valid values are: #{valid}"
95
+ end
96
+ else
97
+ instance_variable_set ivar_name(key), values.first
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Spreadsheet::Encoding -- spreadheet -- 07.09.2011 -- mhatakeyama@ywesee.com
4
+ # Spreadsheet::Encoding -- spreadheet -- 03.07.2009 -- hwyss@ywesee.com
5
+
6
+ module Spreadsheet
7
+ ##
8
+ # Methods for Encoding-conversions. You should not need to use any of these.
9
+ module Encodings
10
+ if RUBY_VERSION >= '1.9'
11
+ def client string, internal='UTF-16LE'
12
+ string = string.dup
13
+ string.force_encoding internal
14
+ string.encode Spreadsheet.client_encoding
15
+ end
16
+ def internal string, client=Spreadsheet.client_encoding
17
+ string = string.dup
18
+ string.force_encoding client
19
+ string.encode('UTF-16LE').force_encoding('ASCII-8BIT')
20
+ end
21
+ def utf8 string, client=Spreadsheet.client_encoding
22
+ string = string.dup
23
+ string.force_encoding client
24
+ string.encode('UTF-8')
25
+ end
26
+ else
27
+ require 'iconv'
28
+ @@iconvs = {}
29
+ def client string, internal='UTF-16LE'
30
+ string = string.dup
31
+ key = [Spreadsheet.client_encoding, internal]
32
+ iconv = @@iconvs[key] ||= Iconv.new(Spreadsheet.client_encoding, internal)
33
+ iconv.iconv string
34
+ end
35
+ def internal string, client=Spreadsheet.client_encoding
36
+ string = string.dup
37
+ key = ['UTF-16LE', client]
38
+ iconv = @@iconvs[key] ||= Iconv.new('UTF-16LE', client)
39
+ iconv.iconv string
40
+ end
41
+ def utf8 string, client=Spreadsheet.client_encoding
42
+ string = string.dup
43
+ key = ['UTF-8', client]
44
+ iconv = @@iconvs[key] ||= Iconv.new('UTF-8', client)
45
+ iconv.iconv string
46
+ end
47
+ end
48
+ rescue LoadError
49
+ warn "You don't have Iconv support compiled in your Ruby. Spreadsheet may not work as expected"
50
+ def client string, internal='UTF-16LE'
51
+ string.delete "\0"
52
+ end
53
+ def internal string, internal='UTF-16LE'
54
+ string.split('').zip(Array.new(string.size, 0.chr)).join
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,88 @@
1
+ require 'spreadsheet'
2
+
3
+ warn <<-EOS
4
+ [DEPRECATED] By requiring 'spreadsheet/excel' you are loading a Compatibility
5
+ layer which provides a drop-in replacement for Spreadsheet::Excel
6
+ versions <= 0.3.5.1. This code will be removed in Spreadsheet
7
+ version 1.0.0
8
+ EOS
9
+ ##
10
+ # Spreadsheet::Excel Compatibility Layer.
11
+ # Drop-in replacement for Spreadsheet::Excel version <= 0.3.5.1
12
+ module Spreadsheet
13
+ module Excel
14
+ class ExcelCompatibleWorkbook < Workbook
15
+ def initialize file_path, *args
16
+ super *args
17
+ @file_path = file_path
18
+ end
19
+ def close
20
+ write @file_path
21
+ end
22
+ end
23
+ def Excel.new file_path
24
+ ExcelCompatibleWorkbook.new file_path
25
+ end
26
+ class Workbook
27
+ def add_worksheet name
28
+ if name.is_a? String
29
+ create_worksheet :name => name
30
+ else
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
36
+ class Worksheet
37
+ unless instance_methods.include? "new_format_column"
38
+ alias :new_format_column :format_column
39
+ def format_column column, width=nil, format=nil
40
+ if width.is_a? Format
41
+ new_format_column column, width, format
42
+ else
43
+ new_format_column column, format, :width => width
44
+ end
45
+ end
46
+ end
47
+ def write row, col, data=nil, format=nil
48
+ if data.is_a? Array
49
+ write_row row, col, data, format
50
+ else
51
+ row = row(row)
52
+ row[col] = data
53
+ row.set_format col, format
54
+ end
55
+ end
56
+ def write_column row, col, data=nil, format=nil
57
+ if data.is_a? Array
58
+ data.each do |token|
59
+ if token.is_a? Array
60
+ write_row row, col, token, format
61
+ else
62
+ write row, col, token, format
63
+ end
64
+ row += 1
65
+ end
66
+ else
67
+ write row, col, data, format
68
+ end
69
+ end
70
+ def write_row row, col, data=nil, format=nil
71
+ if data.is_a? Array
72
+ data.each do |token|
73
+ if token.is_a? Array
74
+ write_column row, col, token, format
75
+ else
76
+ write row, col, token, format
77
+ end
78
+ col += 1
79
+ end
80
+ else
81
+ write row, col, data, format
82
+ end
83
+ end
84
+ def write_url row, col, url, string=url, format=nil
85
+ row(row)[col] = Link.new url, string
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,26 @@
1
+ module Spreadsheet
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
25
+ end
26
+ end
@@ -0,0 +1,361 @@
1
+ require 'date'
2
+
3
+ module Spreadsheet
4
+ module Excel
5
+ ##
6
+ # Binary Formats and other configurations internal to Excel. This Module is
7
+ # likely to shrink as Support for older Versions of Excel grows and more Binary
8
+ # formats are moved away from here for disambiguation.
9
+ # If you need to work with constants defined in this module and are confused by
10
+ # names like SEDOC_ROLOC, try reading them backwards. (The reason for this weird
11
+ # naming convention is that according to my ri, Ruby 1.9 renames Hash#index to
12
+ # Hash#key without backward compatibility. Since I did not want to pepper my code
13
+ # with RUBY_VERSION-checks, I settled on this strategy to make the transition to
14
+ # Ruby 1.9 as simple as possible.
15
+ module Internals
16
+ EIGHT_BYTE_DOUBLE = [0.1].pack('E').size == 8 ? 'E' : 'e'
17
+ CODEPAGES = {
18
+ 367 => "ASCII",
19
+ 437 => "IBM437", #(US)
20
+ 720 => "IBM720", #(OEM Arabic)
21
+ 737 => "IBM737", #(Greek)
22
+ 775 => "IBM775", #(Baltic)
23
+ 850 => "IBM850", #(Latin I)
24
+ 852 => "IBM852", #(Latin II (Central European))
25
+ 855 => "IBM855", #(Cyrillic)
26
+ 857 => "IBM857", #(Turkish)
27
+ 858 => "IBM858", #(Multilingual Latin I with Euro)
28
+ 860 => "IBM860", #(Portuguese)
29
+ 861 => "IBM861", #(Icelandic)
30
+ 862 => "IBM862", #(Hebrew)
31
+ 863 => "IBM863", #(Canadian (French))
32
+ 864 => "IBM864", #(Arabic)
33
+ 865 => "IBM865", #(Nordic)
34
+ 866 => "IBM866", #(Cyrillic (Russian))
35
+ 869 => "IBM869", #(Greek (Modern))
36
+ 874 => "WINDOWS-874", #(Thai)
37
+ 932 => "WINDOWS-932", #(Japanese Shift-JIS)
38
+ 936 => "WINDOWS-936", #(Chinese Simplified GBK)
39
+ 949 => "WINDOWS-949", #(Korean (Wansung))
40
+ 950 => "WINDOWS-950", #(Chinese Traditional BIG5)
41
+ 1200 => "UTF-16LE", #(BIFF8)
42
+ 1250 => "WINDOWS-1250", #(Latin II) (Central European)
43
+ 1251 => "WINDOWS-1251", #(Cyrillic)
44
+ 1252 => "WINDOWS-1252", #(Latin I) (BIFF4-BIFF7)
45
+ 1253 => "WINDOWS-1253", #(Greek)
46
+ 1254 => "WINDOWS-1254", #(Turkish)
47
+ 1255 => "WINDOWS-1255", #(Hebrew)
48
+ 1256 => "WINDOWS-1256", #(Arabic)
49
+ 1257 => "WINDOWS-1257", #(Baltic)
50
+ 1258 => "WINDOWS-1258", #(Vietnamese)
51
+ 1361 => "WINDOWS-1361", #(Korean (Johab))
52
+ 10000 => "MACINTOSH",
53
+ 32768 => "MACINTOSH",
54
+ 32769 => "WINDOWS-1252", #(Latin I) (BIFF2-BIFF3)
55
+ }
56
+ SEGAPEDOC = CODEPAGES.invert
57
+ COLOR_CODES = {
58
+ 0x0000 => :builtin_black,
59
+ 0x0001 => :builtin_white,
60
+ 0x0002 => :builtin_red,
61
+ 0x0003 => :builtin_green,
62
+ 0x0004 => :builtin_blue,
63
+ 0x0005 => :builtin_yellow,
64
+ 0x0006 => :builtin_magenta,
65
+ 0x0007 => :builtin_cyan,
66
+ 0x0008 => :black,
67
+ 0x0009 => :white,
68
+ 0x000a => :red,
69
+ 0x000b => :lime,
70
+ 0x000c => :blue,
71
+ 0x000d => :yellow,
72
+ 0x000e => :magenta,
73
+ 0x000f => :cyan,
74
+ 0x0010 => :brown,
75
+ 0x0011 => :green,
76
+ 0x0012 => :navy,
77
+ 0x0016 => :silver,
78
+ 0x0017 => :gray,
79
+ 0x0034 => :orange,
80
+ 0x0024 => :purple,
81
+ 0x0040 => :border,
82
+ 0x0041 => :pattern_bg,
83
+ 0x0043 => :dialog_bg,
84
+ 0x004d => :chart_text,
85
+ 0x004e => :chart_bg,
86
+ 0x004f => :chart_border,
87
+ 0x0050 => :tooltip_bg,
88
+ 0x0051 => :tooltip_text,
89
+ 0x7fff => :text,
90
+ }
91
+ SEDOC_ROLOC = COLOR_CODES.invert.update( :aqua => 0x000f,
92
+ :fuchsia => 0x000e,
93
+ :grey => 0x0017 )
94
+ BINARY_FORMATS = {
95
+ :blank => 'v3',
96
+ :boolerr => 'v3C2',
97
+ :colinfo => 'v5x2',
98
+ :font => 'v5C3x',
99
+ :labelsst => 'v3V',
100
+ :number => "v3#{EIGHT_BYTE_DOUBLE}",
101
+ :pagesetup => "v8#{EIGHT_BYTE_DOUBLE}2v",
102
+ :rk => 'v3V',
103
+ :row => 'v4x4V',
104
+ :window2 => 'v4x2v2x4',
105
+ :xf => 'v3C4V2v',
106
+ }
107
+ # From BIFF5 on, the built-in number formats will be omitted. The built-in
108
+ # formats are dependent on the current regional settings of the operating
109
+ # system. The following table shows which number formats are used by
110
+ # default in a US-English environment. All indexes from 0 to 163 are
111
+ # reserved for built-in formats.
112
+ BUILTIN_FORMATS = { # TODO: locale support
113
+ 0 => 'GENERAL',
114
+ 1 => '0',
115
+ 2 => '0.00',
116
+ 3 => '#,##0',
117
+ 4 => '#,##0.00',
118
+ 5 => '"$"#,##0_);("$"#,##0)',
119
+ 6 => '"$"#,##0_);[Red]("$"#,##0)',
120
+ 7 => '"$"#,##0.00_);("$"#,##0.00)',
121
+ 8 => '"$"#,##0.00_);[Red]("$"#,##0.00)',
122
+ 9 => '0%',
123
+ 10 => '0.00%',
124
+ 11 => '0.00E+00',
125
+ 12 => '# ?/?',
126
+ 13 => '# ??/??',
127
+ 14 => 'M/D/YY',
128
+ 15 => 'D-MMM-YY',
129
+ 16 => 'D-MMM',
130
+ 17 => 'MMM-YY',
131
+ 18 => 'h:mm AM/PM',
132
+ 19 => 'h:mm:ss AM/PM',
133
+ 20 => 'h:mm',
134
+ 21 => 'h:mm:ss',
135
+ 22 => 'M/D/YY h:mm',
136
+ 37 => '_(#,##0_);(#,##0)',
137
+ 38 => '_(#,##0_);[Red](#,##0)',
138
+ 39 => '_(#,##0.00_);(#,##0.00)',
139
+ 40 => '_(#,##0.00_);[Red](#,##0.00)',
140
+ 41 => '_("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)',
141
+ 42 => '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',
142
+ 43 => '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)',
143
+ 44 => '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',
144
+ 45 => 'mm:ss',
145
+ 46 => '[h]:mm:ss',
146
+ 47 => 'mm:ss.0',
147
+ 48 => '##0.0E+0',
148
+ 49 => '@',
149
+ }
150
+ BUILTIN_STYLES = {
151
+ 0x00 => 'Normal',
152
+ 0x01 => 'RowLevel_lv',
153
+ 0x02 => 'ColLevel_lv',
154
+ 0x03 => 'Comma',
155
+ 0x04 => 'Currency',
156
+ 0x05 => 'Percent',
157
+ 0x06 => 'Comma',
158
+ 0x07 => 'Currency',
159
+ 0x08 => 'Hyperlink',
160
+ 0x09 => 'Followed Hyperlink',
161
+ }
162
+ ESCAPEMENT_TYPES = {
163
+ 0x0001 => :superscript,
164
+ 0x0002 => :subscript,
165
+ }
166
+ SEPYT_TNEMEPACSE = ESCAPEMENT_TYPES.invert
167
+ FONT_ENCODINGS = {
168
+ 0x00 => :iso_latin1,
169
+ 0x01 => :default,
170
+ 0x02 => :symbol,
171
+ 0x4d => :apple_roman,
172
+ 0x80 => :shift_jis,
173
+ 0x81 => :korean_hangul,
174
+ 0x82 => :korean_johab,
175
+ 0x86 => :chinese_simplified,
176
+ 0x88 => :chinese_traditional,
177
+ 0xa1 => :greek,
178
+ 0xa2 => :turkish,
179
+ 0xa3 => :vietnamese,
180
+ 0xb1 => :hebrew,
181
+ 0xb2 => :arabic,
182
+ 0xba => :baltic,
183
+ 0xcc => :cyrillic,
184
+ 0xde => :thai,
185
+ 0xee => :iso_latin2,
186
+ 0xff => :oem_latin1,
187
+ }
188
+ SGNIDOCNE_TNOF = FONT_ENCODINGS.invert
189
+ FONT_FAMILIES = {
190
+ 0x01 => :roman,
191
+ 0x02 => :swiss,
192
+ 0x03 => :modern,
193
+ 0x04 => :script,
194
+ 0x05 => :decorative,
195
+ }
196
+ SEILIMAF_TNOF = FONT_FAMILIES.invert
197
+ FONT_WEIGHTS = {
198
+ :bold => 700,
199
+ :normal => 400,
200
+ }
201
+ LEAP_ERROR = Date.new 1900, 2, 28
202
+ OPCODES = {
203
+ :blank => 0x0201, # BLANK ➜ 6.7
204
+ :boolerr => 0x0205, # BOOLERR ➜ 6.10
205
+ :boundsheet => 0x0085, # ●● BOUNDSHEET ➜ 6.12
206
+ :codepage => 0x0042, # ○ CODEPAGE ➜ 6.17
207
+ :colinfo => 0x007d, # ○○ COLINFO ➜ 6.18
208
+ :continue => 0x003c, # ○ CONTINUE ➜ 6.22
209
+ :datemode => 0x0022, # ○ DATEMODE ➜ 6.25
210
+ :dbcell => 0x0a0b, # ○ DBCELL
211
+ :dimensions => 0x0200, # ● DIMENSIONS ➜ 6.31
212
+ :eof => 0x000a, # ● EOF ➜ 6.36
213
+ :font => 0x0031, # ●● FONT ➜ 6.43
214
+ :format => 0x041e, # ○○ FORMAT (Number Format) ➜ 6.45
215
+ :formula => 0x0006, # FORMULA ➜ 6.46
216
+ :hlink => 0x01b8, # HLINK ➜ 6.52 (BIFF8 only)
217
+ :label => 0x0204, # LABEL ➜ 6.59 (BIFF2-BIFF7)
218
+ :labelsst => 0x00fd, # LABELSST ➜ 6.61 (BIFF8 only)
219
+ :mulblank => 0x00be, # MULBLANK ➜ 6.64 (BIFF5-BIFF8)
220
+ :mulrk => 0x00bd, # MULRK ➜ 6.65 (BIFF5-BIFF8)
221
+ :number => 0x0203, # NUMBER ➜ 6.68
222
+ :rk => 0x027e, # RK ➜ 6.82 (BIFF3-BIFF8)
223
+ :row => 0x0208, # ● ROW ➜ 6.83
224
+ :rstring => 0x00d6, # RSTRING ➜ 6.84 (BIFF5/BIFF7)
225
+ :sst => 0x00fc, # ● SST ➜ 6.96
226
+ :string => 0x0207, # STRING ➜ 6.98
227
+ :style => 0x0293, # ●● STYLE ➜ 6.99
228
+ :xf => 0x00e0, # ●● XF ➜ 6.115
229
+ :sharedfmla => 0x04bc, # SHAREDFMLA ➜ 5.94
230
+ ########################## Unhandled Opcodes ################################
231
+ :extsst => 0x00ff, # ● EXTSST ➜ 6.40
232
+ :index => 0x020b, # ○ INDEX ➜ 5.7 (Row Blocks), ➜ 6.55
233
+ :uncalced => 0x005e, # ○ UNCALCED ➜ 6.104
234
+ ########################## ○ Calculation Settings Block ➜ 5.3
235
+ :calccount => 0x000c, # ○ CALCCOUNT ➜ 6.14
236
+ :calcmode => 0x000d, # ○ CALCMODE ➜ 6.15
237
+ :precision => 0x000e, # ○ PRECISION ➜ 6.74 (moved to Workbook Globals
238
+ # Substream in BIFF5-BIFF8)
239
+ :refmode => 0x000f, # ○ REFMODE ➜ 6.80
240
+ :delta => 0x0010, # ○ DELTA ➜ 6.30
241
+ :iteration => 0x0011, # ○ ITERATION ➜ 6.57
242
+ :saverecalc => 0x005f, # ○ SAVERECALC ➜ 6.85 (BIFF3-BIFF8 only)
243
+ ########################## ○ Workbook Protection Block ➜ 5.18
244
+ :protect => 0x0012, # ○ PROTECT
245
+ # Worksheet contents: 1 = protected (➜ 6.77)
246
+ :windowprot => 0x0019, # ○ WINDOWPROTECT Window settings: 1 = protected
247
+ # (BIFF4W only, ➜ 6.110)
248
+ :objectprot => 0x0063, # ○ OBJECTPROTECT
249
+ # Embedded objects: 1 = protected (➜ 6.69)
250
+ :scenprotect => 0x00dd, # ○ SCENPROTECT
251
+ # Scenarios: 1 = protected (BIFF5-BIFF8, ➜ 6.86)
252
+ :password => 0x0013, # ○ PASSWORD Hash value of the password;
253
+ # 0 = no password (➜ 6.72)
254
+ ########################## ○ File Protection Block ➜ 5.19
255
+ :writeprot => 0x0086, # ○ WRITEPROT File is write protected
256
+ # (BIFF3-BIFF8, ➜ 6.112), password in FILESHARING
257
+ :filepass => 0x002f, # ○ FILEPASS File is read/write-protected,
258
+ # encryption information (➜ 6.41)
259
+ :writeaccess => 0x005c, # ○ WRITEACCESS User name (BIFF3-BIFF8, ➜ 6.111)
260
+ :filesharing => 0x005b, # ○ FILESHARING File sharing options
261
+ # (BIFF3-BIFF8, ➜ 6.42)
262
+ ########################## ○ Link Table ➜ 5.10.3
263
+ # ●● SUPBOOK Block(s)
264
+ # Settings for a referenced document
265
+ :supbook => 0x01ae, # ● SUPBOOK ➜ 6.100
266
+ :externname => 0x0223, # ○○ EXTERNNAME ➜ 6.38
267
+ :xct => 0x0059, # ○○ ● XCT ➜ 6.114
268
+ :crn => 0x005a, # ●● CRN ➜ 6.24
269
+ :externsheet => 0x0017, # ● EXTERNSHEET ➜ 6.39
270
+ :name => 0x0218, # ○○ NAME ➜ 6.66
271
+ ##########################
272
+ :window1 => 0x003d, # ● WINDOW1 ➜ 6.108 (has information on
273
+ # which Spreadsheet is 'active')
274
+ :backup => 0x0040, # ○ BACKUP ➜ 6.5
275
+ :country => 0x008c, # ○ COUNTRY (Make writeable?) ➜ 6.23
276
+ :hideobj => 0x008d, # ○ HIDEOBJ ➜ 6.52
277
+ :palette => 0x0092, # ○ PALETTE ➜ 6.70
278
+ :fngroupcnt => 0x009c, # ○ FNGROUPCOUNT
279
+ :bookbool => 0x00da, # ○ BOOKBOOL ➜ 6.9
280
+ :tabid => 0x013d, # ○ TABID
281
+ :useselfs => 0x0160, # ○ USESELFS (Natural Language Formulas) ➜ 6.105
282
+ :dsf => 0x0161, # ○ DSF (Double Stream File) ➜ 6.32
283
+ :refreshall => 0x01b7, # ○ REFRESHALL
284
+ ########################## ● Worksheet View Settings Block ➜ 5.5
285
+ :window2 => 0x023e, # ● WINDOW2 ➜ 5.110
286
+ :scl => 0x00a0, # ○ SCL ➜ 5.92 (BIFF4-BIFF8 only)
287
+ :pane => 0x0041, # ○ PANE ➜ 5.75
288
+ :selection => 0x001d, # ○○ SELECTION ➜ 5.93
289
+ ########################## ○ Page Settings Block ➜ 5.4
290
+ :hpagebreaks => 0x001b, # ○ HORIZONTALPAGEBREAKS ➜ 6.54
291
+ :vpagebreaks => 0x001a, # ○ VERTICALPAGEBREAKS ➜ 6.107
292
+ :header => 0x0014, # ○ HEADER ➜ 6.51
293
+ :footer => 0x0015, # ○ FOOTER ➜ 6.44
294
+ :hcenter => 0x0083, # ○ HCENTER ➜ 6.50 (BIFF3-BIFF8 only)
295
+ :vcenter => 0x0084, # ○ VCENTER ➜ 6.106 (BIFF3-BIFF8 only)
296
+ :leftmargin => 0x0026, # ○ LEFTMARGIN ➜ 6.62
297
+ :rightmargin => 0x0027, # ○ RIGHTMARGIN ➜ 6.81
298
+ :topmargin => 0x0028, # ○ TOPMARGIN ➜ 6.103
299
+ :bottommargin => 0x0029, # ○ BOTTOMMARGIN ➜ 6.11
300
+ # ○ PLS (opcode unknown)
301
+ :pagesetup => 0x00a1, # ○ PAGESETUP ➜ 6.89 (BIFF4-BIFF8 only)
302
+ :bitmap => 0x00e9, # ○ BITMAP ➜ 6.6 (Background-Bitmap, BIFF8 only)
303
+ ##########################
304
+ :printheaders => 0x002a, # ○ PRINTHEADERS ➜ 6.76
305
+ :printgridlns => 0x002b, # ○ PRINTGRIDLINES ➜ 6.75
306
+ :gridset => 0x0082, # ○ GRIDSET ➜ 6.48
307
+ :guts => 0x0080, # ○ GUTS ➜ 6.49
308
+ :defrowheight => 0x0225, # ○ DEFAULTROWHEIGHT ➜ 6.28
309
+ :wsbool => 0x0081, # ○ WSBOOL ➜ 6.113
310
+ :defcolwidth => 0x0055, # ○ DEFCOLWIDTH ➜ 6.29
311
+ :sort => 0x0090, # ○ SORT ➜ 6.95
312
+ }
313
+ =begin ## unknown opcodes
314
+ 0x00bf, 0x00c0, 0x00c1, 0x00e1, 0x00e2, 0x00eb, 0x01af, 0x01bc
315
+ =end
316
+ SEDOCPO = OPCODES.invert
317
+ TWIPS = 20
318
+ UNDERLINE_TYPES = {
319
+ 0x0001 => :single,
320
+ 0x0002 => :double,
321
+ 0x0021 => :single_accounting,
322
+ 0x0022 => :double_accounting,
323
+ }
324
+ SEPYT_ENILREDNU = UNDERLINE_TYPES.invert
325
+ XF_H_ALIGN = {
326
+ :default => 0,
327
+ :left => 1,
328
+ :center => 2,
329
+ :right => 3,
330
+ :fill => 4,
331
+ :justify => 5,
332
+ :merge => 6,
333
+ :distributed => 7,
334
+ }
335
+ NGILA_H_FX = XF_H_ALIGN.invert
336
+ XF_TEXT_DIRECTION = {
337
+ :context => 0,
338
+ :left_to_right => 1,
339
+ :right_to_left => 2,
340
+ }
341
+ NOITCERID_TXET_FX = XF_TEXT_DIRECTION.invert
342
+ XF_V_ALIGN = {
343
+ :top => 0,
344
+ :middle => 1,
345
+ :bottom => 2,
346
+ :justify => 3,
347
+ :distributed => 4,
348
+ }
349
+ NGILA_V_FX = XF_V_ALIGN.invert
350
+ OPCODE_SIZE = 4
351
+ ROW_HEIGHT = 12.1
352
+ SST_CHUNKSIZE = 20
353
+ def binfmt key
354
+ BINARY_FORMATS[key]
355
+ end
356
+ def opcode key
357
+ OPCODES[key]
358
+ end
359
+ end
360
+ end
361
+ end