keeguon-spreadsheet 0.9.3

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 (76) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +619 -0
  3. data/Manifest.txt +85 -0
  4. data/bin/xlsopcodes +18 -0
  5. data/lib/parseexcel.rb +27 -0
  6. data/lib/parseexcel/parseexcel.rb +75 -0
  7. data/lib/parseexcel/parser.rb +11 -0
  8. data/lib/spreadsheet.rb +80 -0
  9. data/lib/spreadsheet/column.rb +71 -0
  10. data/lib/spreadsheet/compatibility.rb +23 -0
  11. data/lib/spreadsheet/datatypes.rb +161 -0
  12. data/lib/spreadsheet/encodings.rb +57 -0
  13. data/lib/spreadsheet/excel.rb +88 -0
  14. data/lib/spreadsheet/excel/error.rb +26 -0
  15. data/lib/spreadsheet/excel/internals.rb +458 -0
  16. data/lib/spreadsheet/excel/internals/biff5.rb +17 -0
  17. data/lib/spreadsheet/excel/internals/biff8.rb +19 -0
  18. data/lib/spreadsheet/excel/offset.rb +41 -0
  19. data/lib/spreadsheet/excel/password_hash.rb +24 -0
  20. data/lib/spreadsheet/excel/reader.rb +1302 -0
  21. data/lib/spreadsheet/excel/reader/biff5.rb +42 -0
  22. data/lib/spreadsheet/excel/reader/biff8.rb +231 -0
  23. data/lib/spreadsheet/excel/rgb.rb +122 -0
  24. data/lib/spreadsheet/excel/row.rb +98 -0
  25. data/lib/spreadsheet/excel/sst_entry.rb +46 -0
  26. data/lib/spreadsheet/excel/workbook.rb +80 -0
  27. data/lib/spreadsheet/excel/worksheet.rb +115 -0
  28. data/lib/spreadsheet/excel/writer.rb +1 -0
  29. data/lib/spreadsheet/excel/writer/biff8.rb +75 -0
  30. data/lib/spreadsheet/excel/writer/format.rb +264 -0
  31. data/lib/spreadsheet/excel/writer/n_worksheet.rb +888 -0
  32. data/lib/spreadsheet/excel/writer/workbook.rb +735 -0
  33. data/lib/spreadsheet/excel/writer/worksheet.rb +940 -0
  34. data/lib/spreadsheet/font.rb +115 -0
  35. data/lib/spreadsheet/format.rb +209 -0
  36. data/lib/spreadsheet/formula.rb +9 -0
  37. data/lib/spreadsheet/helpers.rb +11 -0
  38. data/lib/spreadsheet/link.rb +43 -0
  39. data/lib/spreadsheet/note.rb +23 -0
  40. data/lib/spreadsheet/noteObject.rb +17 -0
  41. data/lib/spreadsheet/row.rb +151 -0
  42. data/lib/spreadsheet/workbook.rb +143 -0
  43. data/lib/spreadsheet/worksheet.rb +326 -0
  44. data/lib/spreadsheet/writer.rb +30 -0
  45. data/test/data/test_adding_data_to_existing_file.xls +0 -0
  46. data/test/data/test_borders.xls +0 -0
  47. data/test/data/test_changes.xls +0 -0
  48. data/test/data/test_comment.xls +0 -0
  49. data/test/data/test_copy.xls +0 -0
  50. data/test/data/test_datetime.xls +0 -0
  51. data/test/data/test_empty.xls +0 -0
  52. data/test/data/test_formula.xls +0 -0
  53. data/test/data/test_long_sst_record.xls +0 -0
  54. data/test/data/test_margin.xls +0 -0
  55. data/test/data/test_merged_and_protected.xls +0 -0
  56. data/test/data/test_merged_cells.xls +0 -0
  57. data/test/data/test_missing_row.xls +0 -0
  58. data/test/data/test_pagesetup.xls +0 -0
  59. data/test/data/test_version_excel5.xls +0 -0
  60. data/test/data/test_version_excel95.xls +0 -0
  61. data/test/data/test_version_excel97.xls +0 -0
  62. data/test/data/test_version_excel97_2010.xls +0 -0
  63. data/test/data/test_worksheet_visibility.xls +0 -0
  64. data/test/excel/reader.rb +30 -0
  65. data/test/excel/row.rb +40 -0
  66. data/test/excel/writer/workbook.rb +95 -0
  67. data/test/excel/writer/worksheet.rb +81 -0
  68. data/test/font.rb +163 -0
  69. data/test/format.rb +95 -0
  70. data/test/integration.rb +1390 -0
  71. data/test/row.rb +33 -0
  72. data/test/suite.rb +18 -0
  73. data/test/workbook.rb +55 -0
  74. data/test/workbook_protection.rb +19 -0
  75. data/test/worksheet.rb +112 -0
  76. metadata +148 -0
@@ -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//TRANSLIT//IGNORE', 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//TRANSLIT//IGNORE', 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,458 @@
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 => "MACROMAN",
53
+ 32768 => "MACROMAN",
54
+ 32769 => "WINDOWS-1252", #(Latin I) (BIFF2-BIFF3)
55
+ }
56
+ SEGAPEDOC = CODEPAGES.invert
57
+ # color_codes according to http://support.softartisans.com/kbview_1205.aspx
58
+ # synonyms are in comments when reverse lookup
59
+ COLOR_CODES = {
60
+ 0x0000 => :builtin_black,
61
+ 0x0001 => :builtin_white,
62
+ 0x0002 => :builtin_red,
63
+ 0x0003 => :builtin_green,
64
+ 0x0004 => :builtin_blue,
65
+ 0x0005 => :builtin_yellow,
66
+ 0x0006 => :builtin_magenta,
67
+ 0x0007 => :builtin_cyan,
68
+ 0x0008 => :black, #xls_color_0
69
+ 0x0009 => :white, #xls_color_1
70
+ 0x000a => :red, #xls_color_2
71
+ 0x000b => :lime, #xls_color_3
72
+ 0x000c => :blue, #xls_color_4
73
+ 0x000d => :yellow, #xls_color_5
74
+ 0x000e => :magenta, #xls_color_6, fuchsia
75
+ 0x000f => :cyan, #xls_color_7, aqua
76
+ 0x0010 => :brown, #xls_color_8
77
+ 0x0011 => :green, #xls_color_9
78
+ 0x0012 => :navy, #xls_color_10
79
+ 0x0013 => :xls_color_11,
80
+ 0x0014 => :xls_color_12,
81
+ 0x0015 => :xls_color_13,
82
+ 0x0016 => :silver, #xls_color_14
83
+ 0x0017 => :gray, #xls_color_15, grey
84
+ 0x0018 => :xls_color_16,
85
+ 0x0019 => :xls_color_17,
86
+ 0x001a => :xls_color_18,
87
+ 0x001b => :xls_color_19,
88
+ 0x001c => :xls_color_20,
89
+ 0x001d => :xls_color_21,
90
+ 0x001e => :xls_color_22,
91
+ 0x001f => :xls_color_23,
92
+ 0x0020 => :xls_color_24,
93
+ 0x0021 => :xls_color_25,
94
+ 0x0022 => :xls_color_26,
95
+ 0x0023 => :xls_color_27,
96
+ 0x0024 => :purple, #xls_color_28
97
+ 0x0025 => :xls_color_29,
98
+ 0x0026 => :xls_color_30,
99
+ 0x0027 => :xls_color_31,
100
+ 0x0028 => :xls_color_32,
101
+ 0x0029 => :xls_color_33,
102
+ 0x002a => :xls_color_34,
103
+ 0x002b => :xls_color_35,
104
+ 0x002c => :xls_color_36,
105
+ 0x002d => :xls_color_37,
106
+ 0x002e => :xls_color_38,
107
+ 0x002f => :xls_color_39,
108
+ 0x0030 => :xls_color_40,
109
+ 0x0031 => :xls_color_41,
110
+ 0x0032 => :xls_color_42,
111
+ 0x0033 => :xls_color_43,
112
+ 0x0034 => :orange, #xls_color_44
113
+ 0x0035 => :xls_color_45,
114
+ 0x0036 => :xls_color_46,
115
+ 0x0037 => :xls_color_47,
116
+ 0x0038 => :xls_color_48,
117
+ 0x0039 => :xls_color_49,
118
+ 0x003a => :xls_color_50,
119
+ 0x003b => :xls_color_51,
120
+ 0x003c => :xls_color_52,
121
+ 0x003d => :xls_color_53,
122
+ 0x003e => :xls_color_54,
123
+ 0x003f => :xls_color_55,
124
+
125
+ 0x0040 => :border,
126
+ 0x0041 => :pattern_bg,
127
+ 0x0043 => :dialog_bg,
128
+ 0x004d => :chart_text,
129
+ 0x004e => :chart_bg,
130
+ 0x004f => :chart_border,
131
+ 0x0050 => :tooltip_bg,
132
+ 0x0051 => :tooltip_text,
133
+ 0x7fff => :text
134
+ }
135
+
136
+ SEDOC_ROLOC = COLOR_CODES.invert.update(
137
+ :xls_color_0 => 0x0008,
138
+ :xls_color_1 => 0x0009,
139
+ :xls_color_2 => 0x000a,
140
+ :xls_color_3 => 0x000b,
141
+ :xls_color_4 => 0x000c,
142
+ :xls_color_5 => 0x000d,
143
+ :xls_color_6 => 0x000e,
144
+ :fuchsia => 0x000e,
145
+ :xls_color_7 => 0x000f,
146
+ :aqua => 0x000f,
147
+ :xls_color_8 => 0x0010,
148
+ :xls_color_9 => 0x0011,
149
+ :xls_color_10 => 0x0012,
150
+ :xls_color_14 => 0x0016,
151
+ :xls_color_15 => 0x0017,
152
+ :grey => 0x0017,
153
+ :xls_color_28 => 0x0024,
154
+ :xls_color_44 => 0x0034
155
+ )
156
+
157
+ BINARY_FORMATS = {
158
+ :blank => 'v3',
159
+ :boolerr => 'v3C2',
160
+ :colinfo => 'v5x2',
161
+ :font => 'v5C3x',
162
+ :labelsst => 'v3V',
163
+ :number => "v3#{EIGHT_BYTE_DOUBLE}",
164
+ :pagesetup => "v8#{EIGHT_BYTE_DOUBLE}2v",
165
+ :margin => "#{EIGHT_BYTE_DOUBLE}",
166
+ :rk => 'v3V',
167
+ :row => 'v4x4V',
168
+ :window2 => 'v4x2v2x4',
169
+ :xf => 'v3C4V2v',
170
+ }
171
+ # From BIFF5 on, the built-in number formats will be omitted. The built-in
172
+ # formats are dependent on the current regional settings of the operating
173
+ # system. The following table shows which number formats are used by
174
+ # default in a US-English environment. All indexes from 0 to 163 are
175
+ # reserved for built-in formats.
176
+ BUILTIN_FORMATS = { # TODO: locale support
177
+ 0 => 'GENERAL',
178
+ 1 => '0',
179
+ 2 => '0.00',
180
+ 3 => '#,##0',
181
+ 4 => '#,##0.00',
182
+ 5 => '"$"#,##0_);("$"#,##0)',
183
+ 6 => '"$"#,##0_);[Red]("$"#,##0)',
184
+ 7 => '"$"#,##0.00_);("$"#,##0.00)',
185
+ 8 => '"$"#,##0.00_);[Red]("$"#,##0.00)',
186
+ 9 => '0%',
187
+ 10 => '0.00%',
188
+ 11 => '0.00E+00',
189
+ 12 => '# ?/?',
190
+ 13 => '# ??/??',
191
+ 14 => 'M/D/YY',
192
+ 15 => 'D-MMM-YY',
193
+ 16 => 'D-MMM',
194
+ 17 => 'MMM-YY',
195
+ 18 => 'h:mm AM/PM',
196
+ 19 => 'h:mm:ss AM/PM',
197
+ 20 => 'h:mm',
198
+ 21 => 'h:mm:ss',
199
+ 22 => 'M/D/YY h:mm',
200
+ 37 => '_(#,##0_);(#,##0)',
201
+ 38 => '_(#,##0_);[Red](#,##0)',
202
+ 39 => '_(#,##0.00_);(#,##0.00)',
203
+ 40 => '_(#,##0.00_);[Red](#,##0.00)',
204
+ 41 => '_("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)',
205
+ 42 => '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',
206
+ 43 => '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)',
207
+ 44 => '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',
208
+ 45 => 'mm:ss',
209
+ 46 => '[h]:mm:ss',
210
+ 47 => 'mm:ss.0',
211
+ 48 => '##0.0E+0',
212
+ 49 => '@',
213
+ }
214
+ BUILTIN_STYLES = {
215
+ 0x00 => 'Normal',
216
+ 0x01 => 'RowLevel_lv',
217
+ 0x02 => 'ColLevel_lv',
218
+ 0x03 => 'Comma',
219
+ 0x04 => 'Currency',
220
+ 0x05 => 'Percent',
221
+ 0x06 => 'Comma',
222
+ 0x07 => 'Currency',
223
+ 0x08 => 'Hyperlink',
224
+ 0x09 => 'Followed Hyperlink',
225
+ }
226
+ ESCAPEMENT_TYPES = {
227
+ 0x0001 => :superscript,
228
+ 0x0002 => :subscript,
229
+ }
230
+ SEPYT_TNEMEPACSE = ESCAPEMENT_TYPES.invert
231
+ FONT_ENCODINGS = {
232
+ 0x00 => :iso_latin1,
233
+ 0x01 => :default,
234
+ 0x02 => :symbol,
235
+ 0x4d => :apple_roman,
236
+ 0x80 => :shift_jis,
237
+ 0x81 => :korean_hangul,
238
+ 0x82 => :korean_johab,
239
+ 0x86 => :chinese_simplified,
240
+ 0x88 => :chinese_traditional,
241
+ 0xa1 => :greek,
242
+ 0xa2 => :turkish,
243
+ 0xa3 => :vietnamese,
244
+ 0xb1 => :hebrew,
245
+ 0xb2 => :arabic,
246
+ 0xba => :baltic,
247
+ 0xcc => :cyrillic,
248
+ 0xde => :thai,
249
+ 0xee => :iso_latin2,
250
+ 0xff => :oem_latin1,
251
+ }
252
+ SGNIDOCNE_TNOF = FONT_ENCODINGS.invert
253
+ FONT_FAMILIES = {
254
+ 0x01 => :roman,
255
+ 0x02 => :swiss,
256
+ 0x03 => :modern,
257
+ 0x04 => :script,
258
+ 0x05 => :decorative,
259
+ }
260
+ SEILIMAF_TNOF = FONT_FAMILIES.invert
261
+ FONT_WEIGHTS = {
262
+ :bold => 700,
263
+ :normal => 400,
264
+ }
265
+ WORKSHEET_VISIBILITIES = {
266
+ 0x00 => :visible,
267
+ 0x01 => :hidden,
268
+ 0x02 => :strong_hidden
269
+ }
270
+ SEITILIBISIV_TEEHSKROW = WORKSHEET_VISIBILITIES.invert
271
+ LEAP_ERROR = Date.new 1900, 2, 28
272
+ OPCODES = {
273
+ :blank => 0x0201, # BLANK ➜ 6.7
274
+ :boolerr => 0x0205, # BOOLERR ➜ 6.10
275
+ :boundsheet => 0x0085, # ●● BOUNDSHEET ➜ 6.12
276
+ :codepage => 0x0042, # ○ CODEPAGE ➜ 6.17
277
+ :colinfo => 0x007d, # ○○ COLINFO ➜ 6.18
278
+ :continue => 0x003c, # ○ CONTINUE ➜ 6.22
279
+ :datemode => 0x0022, # ○ DATEMODE ➜ 6.25
280
+ :dbcell => 0x0a0b, # ○ DBCELL
281
+ :dimensions => 0x0200, # ● DIMENSIONS ➜ 6.31
282
+ :eof => 0x000a, # ● EOF ➜ 6.36
283
+ :font => 0x0031, # ●● FONT ➜ 6.43
284
+ :format => 0x041e, # ○○ FORMAT (Number Format) ➜ 6.45
285
+ :formula => 0x0006, # FORMULA ➜ 6.46
286
+ :hlink => 0x01b8, # HLINK ➜ 6.52 (BIFF8 only)
287
+ :label => 0x0204, # LABEL ➜ 6.59 (BIFF2-BIFF7)
288
+ :labelsst => 0x00fd, # LABELSST ➜ 6.61 (BIFF8 only)
289
+ :mergedcells => 0x00e5, # ○○ MERGEDCELLS ➜ 5.67 (BIFF8 only)
290
+ :mulblank => 0x00be, # MULBLANK ➜ 6.64 (BIFF5-BIFF8)
291
+ :mulrk => 0x00bd, # MULRK ➜ 6.65 (BIFF5-BIFF8)
292
+ :number => 0x0203, # NUMBER ➜ 6.68
293
+ :rk => 0x027e, # RK ➜ 6.82 (BIFF3-BIFF8)
294
+ :row => 0x0208, # ● ROW ➜ 6.83
295
+ :rstring => 0x00d6, # RSTRING ➜ 6.84 (BIFF5/BIFF7)
296
+ :sst => 0x00fc, # ● SST ➜ 6.96
297
+ :string => 0x0207, # STRING ➜ 6.98
298
+ :style => 0x0293, # ●● STYLE ➜ 6.99
299
+ :xf => 0x00e0, # ●● XF ➜ 6.115
300
+ :sharedfmla => 0x04bc, # SHAREDFMLA ➜ 5.94
301
+ ########################## Unhandled Opcodes ################################
302
+ :extsst => 0x00ff, # ● EXTSST ➜ 6.40
303
+ :index => 0x020b, # ○ INDEX ➜ 5.7 (Row Blocks), ➜ 6.55
304
+ :uncalced => 0x005e, # ○ UNCALCED ➜ 6.104
305
+ ########################## ○ Calculation Settings Block ➜ 5.3
306
+ :calccount => 0x000c, # ○ CALCCOUNT ➜ 6.14
307
+ :calcmode => 0x000d, # ○ CALCMODE ➜ 6.15
308
+ :precision => 0x000e, # ○ PRECISION ➜ 6.74 (moved to Workbook Globals
309
+ # Substream in BIFF5-BIFF8)
310
+ :refmode => 0x000f, # ○ REFMODE ➜ 6.80
311
+ :delta => 0x0010, # ○ DELTA ➜ 6.30
312
+ :iteration => 0x0011, # ○ ITERATION ➜ 6.57
313
+ :saverecalc => 0x005f, # ○ SAVERECALC ➜ 6.85 (BIFF3-BIFF8 only)
314
+ ########################## ○ Workbook Protection Block ➜ 5.18
315
+ :protect => 0x0012, # ○ PROTECT
316
+ # Worksheet contents: 1 = protected (➜ 6.77)
317
+ :windowprot => 0x0019, # ○ WINDOWPROTECT Window settings: 1 = protected
318
+ # (BIFF4W only, ➜ 6.110)
319
+ :objectprot => 0x0063, # ○ OBJECTPROTECT
320
+ # Embedded objects: 1 = protected (➜ 6.69)
321
+ :scenprotect => 0x00dd, # ○ SCENPROTECT
322
+ # Scenarios: 1 = protected (BIFF5-BIFF8, ➜ 6.86)
323
+ :password => 0x0013, # ○ PASSWORD Hash value of the password;
324
+ # 0 = no password (➜ 6.72)
325
+ ########################## ○ File Protection Block ➜ 5.19
326
+ :writeprot => 0x0086, # ○ WRITEPROT File is write protected
327
+ # (BIFF3-BIFF8, ➜ 6.112), password in FILESHARING
328
+ :filepass => 0x002f, # ○ FILEPASS File is read/write-protected,
329
+ # encryption information (➜ 6.41)
330
+ :writeaccess => 0x005c, # ○ WRITEACCESS User name (BIFF3-BIFF8, ➜ 6.111)
331
+ :filesharing => 0x005b, # ○ FILESHARING File sharing options
332
+ # (BIFF3-BIFF8, ➜ 6.42)
333
+ ########################## ○ Link Table ➜ 5.10.3
334
+ # ●● SUPBOOK Block(s)
335
+ # Settings for a referenced document
336
+ :supbook => 0x01ae, # ● SUPBOOK ➜ 6.100
337
+ :externname => 0x0223, # ○○ EXTERNNAME ➜ 6.38
338
+ :xct => 0x0059, # ○○ ● XCT ➜ 6.114
339
+ :crn => 0x005a, # ●● CRN ➜ 6.24
340
+ :externsheet => 0x0017, # ● EXTERNSHEET ➜ 6.39
341
+ :name => 0x0218, # ○○ NAME ➜ 6.66
342
+ ##########################
343
+ :window1 => 0x003d, # ● WINDOW1 ➜ 6.108 (has information on
344
+ # which Spreadsheet is 'active')
345
+ :backup => 0x0040, # ○ BACKUP ➜ 6.5
346
+ :country => 0x008c, # ○ COUNTRY (Make writeable?) ➜ 6.23
347
+ :hideobj => 0x008d, # ○ HIDEOBJ ➜ 6.52
348
+ :palette => 0x0092, # ○ PALETTE ➜ 6.70
349
+ :fngroupcnt => 0x009c, # ○ FNGROUPCOUNT
350
+ :bookbool => 0x00da, # ○ BOOKBOOL ➜ 6.9
351
+ :tabid => 0x013d, # ○ TABID
352
+ :useselfs => 0x0160, # ○ USESELFS (Natural Language Formulas) ➜ 6.105
353
+ :dsf => 0x0161, # ○ DSF (Double Stream File) ➜ 6.32
354
+ :refreshall => 0x01b7, # ○ REFRESHALL
355
+ ########################## ● Worksheet View Settings Block ➜ 5.5
356
+ :window2 => 0x023e, # ● WINDOW2 ➜ 5.110
357
+ :scl => 0x00a0, # ○ SCL ➜ 5.92 (BIFF4-BIFF8 only)
358
+ :pane => 0x0041, # ○ PANE ➜ 5.75
359
+ :selection => 0x001d, # ○○ SELECTION ➜ 5.93
360
+ ########################## ○ Page Settings Block ➜ 5.4
361
+ :hpagebreaks => 0x001b, # ○ HORIZONTALPAGEBREAKS ➜ 6.54
362
+ :vpagebreaks => 0x001a, # ○ VERTICALPAGEBREAKS ➜ 6.107
363
+ :header => 0x0014, # ○ HEADER ➜ 6.51
364
+ :footer => 0x0015, # ○ FOOTER ➜ 6.44
365
+ :hcenter => 0x0083, # ○ HCENTER ➜ 6.50 (BIFF3-BIFF8 only)
366
+ :vcenter => 0x0084, # ○ VCENTER ➜ 6.106 (BIFF3-BIFF8 only)
367
+ :leftmargin => 0x0026, # ○ LEFTMARGIN ➜ 6.62
368
+ :rightmargin => 0x0027, # ○ RIGHTMARGIN ➜ 6.81
369
+ :topmargin => 0x0028, # ○ TOPMARGIN ➜ 6.103
370
+ :bottommargin => 0x0029, # ○ BOTTOMMARGIN ➜ 6.11
371
+ # ○ PLS (opcode unknown)
372
+ :pagesetup => 0x00a1, # ○ PAGESETUP ➜ 6.89 (BIFF4-BIFF8 only)
373
+ :bitmap => 0x00e9, # ○ BITMAP ➜ 6.6 (Background-Bitmap, BIFF8 only)
374
+ ##########################
375
+ :printheaders => 0x002a, # ○ PRINTHEADERS ➜ 6.76
376
+ :printgridlns => 0x002b, # ○ PRINTGRIDLINES ➜ 6.75
377
+ :gridset => 0x0082, # ○ GRIDSET ➜ 6.48
378
+ :guts => 0x0080, # ○ GUTS ➜ 6.49
379
+ :defrowheight => 0x0225, # ○ DEFAULTROWHEIGHT ➜ 6.28
380
+ :wsbool => 0x0081, # ○ WSBOOL ➜ 6.113
381
+ :defcolwidth => 0x0055, # ○ DEFCOLWIDTH ➜ 6.29
382
+ :sort => 0x0090, # ○ SORT ➜ 6.95
383
+ :note => 0x001c,
384
+ :obj => 0x005d,
385
+ :drawing => 0x00EC,
386
+ :txo => 0x01B6,
387
+ }
388
+ =begin ## unknown opcodes
389
+ 0x00bf, 0x00c0, 0x00c1, 0x00e1, 0x00e2, 0x00eb, 0x01af, 0x01bc
390
+ =end
391
+ SEDOCPO = OPCODES.invert
392
+ TWIPS = 20
393
+ UNDERLINE_TYPES = {
394
+ 0x0001 => :single,
395
+ 0x0002 => :double,
396
+ 0x0021 => :single_accounting,
397
+ 0x0022 => :double_accounting,
398
+ }
399
+ SEPYT_ENILREDNU = UNDERLINE_TYPES.invert
400
+ XF_H_ALIGN = {
401
+ :default => 0,
402
+ :left => 1,
403
+ :center => 2,
404
+ :right => 3,
405
+ :fill => 4,
406
+ :justify => 5,
407
+ :merge => 6,
408
+ :distributed => 7,
409
+ }
410
+ NGILA_H_FX = XF_H_ALIGN.invert
411
+ XF_TEXT_DIRECTION = {
412
+ :context => 0,
413
+ :left_to_right => 1,
414
+ :right_to_left => 2,
415
+ }
416
+ NOITCERID_TXET_FX = XF_TEXT_DIRECTION.invert
417
+ XF_V_ALIGN = {
418
+ :top => 0,
419
+ :middle => 1,
420
+ :bottom => 2,
421
+ :justify => 3,
422
+ :distributed => 4,
423
+ }
424
+ NGILA_V_FX = XF_V_ALIGN.invert
425
+ # border line styles taken from http://www.openoffice.org/sc/excelfileformat.pdf
426
+ XF_BORDER_LINE_STYLES = {
427
+ 0x00 => :none,
428
+ 0x01 => :thin,
429
+ 0x02 => :medium,
430
+ 0x03 => :dashed,
431
+ 0x04 => :dotted,
432
+ 0x05 => :thick,
433
+ 0x06 => :double,
434
+ 0x07 => :hair,
435
+ # the following are only valid for BIFF8 and higher:
436
+ 0x08 => :medium_dashed,
437
+ 0x09 => :thin_dash_dotted,
438
+ 0x0a => :medium_dash_dotted,
439
+ 0x0b => :thin_dash_dot_dotted,
440
+ 0x0c => :medium_dash_dot_dotted,
441
+ 0x0d => :slanted_medium_dash_dotted
442
+ }
443
+ # ensure reader always gets a valid line style
444
+ XF_BORDER_LINE_STYLES.default = :none
445
+ SELYTS_ENIL_REDROB_FX = XF_BORDER_LINE_STYLES.invert
446
+ SELYTS_ENIL_REDROB_FX.default = 0x00
447
+ OPCODE_SIZE = 4
448
+ ROW_HEIGHT = 12.1
449
+ SST_CHUNKSIZE = 20
450
+ def binfmt key
451
+ BINARY_FORMATS[key]
452
+ end
453
+ def opcode key
454
+ OPCODES[key]
455
+ end
456
+ end
457
+ end
458
+ end