spreadsheet-martica 0.6.5.7.m1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/GUIDE.txt +267 -0
  2. data/History.txt +365 -0
  3. data/LICENSE.txt +619 -0
  4. data/Manifest.txt +62 -0
  5. data/README.txt +107 -0
  6. data/bin/xlsopcodes +18 -0
  7. data/lib/parseexcel/parseexcel.rb +75 -0
  8. data/lib/parseexcel/parser.rb +11 -0
  9. data/lib/parseexcel.rb +27 -0
  10. data/lib/spreadsheet/column.rb +71 -0
  11. data/lib/spreadsheet/compatibility.rb +23 -0
  12. data/lib/spreadsheet/datatypes.rb +116 -0
  13. data/lib/spreadsheet/encodings.rb +57 -0
  14. data/lib/spreadsheet/excel/error.rb +26 -0
  15. data/lib/spreadsheet/excel/internals/biff5.rb +17 -0
  16. data/lib/spreadsheet/excel/internals/biff8.rb +19 -0
  17. data/lib/spreadsheet/excel/internals.rb +402 -0
  18. data/lib/spreadsheet/excel/offset.rb +41 -0
  19. data/lib/spreadsheet/excel/reader/biff5.rb +22 -0
  20. data/lib/spreadsheet/excel/reader/biff8.rb +199 -0
  21. data/lib/spreadsheet/excel/reader.rb +1173 -0
  22. data/lib/spreadsheet/excel/row.rb +92 -0
  23. data/lib/spreadsheet/excel/sst_entry.rb +46 -0
  24. data/lib/spreadsheet/excel/workbook.rb +80 -0
  25. data/lib/spreadsheet/excel/worksheet.rb +100 -0
  26. data/lib/spreadsheet/excel/writer/biff8.rb +75 -0
  27. data/lib/spreadsheet/excel/writer/format.rb +253 -0
  28. data/lib/spreadsheet/excel/writer/workbook.rb +653 -0
  29. data/lib/spreadsheet/excel/writer/worksheet.rb +882 -0
  30. data/lib/spreadsheet/excel/writer.rb +1 -0
  31. data/lib/spreadsheet/excel.rb +88 -0
  32. data/lib/spreadsheet/font.rb +92 -0
  33. data/lib/spreadsheet/format.rb +177 -0
  34. data/lib/spreadsheet/formula.rb +9 -0
  35. data/lib/spreadsheet/helpers.rb +11 -0
  36. data/lib/spreadsheet/link.rb +43 -0
  37. data/lib/spreadsheet/row.rb +132 -0
  38. data/lib/spreadsheet/workbook.rb +126 -0
  39. data/lib/spreadsheet/worksheet.rb +277 -0
  40. data/lib/spreadsheet/writer.rb +30 -0
  41. data/lib/spreadsheet.rb +79 -0
  42. data/test/data/test_changes.xls +0 -0
  43. data/test/data/test_copy.xls +0 -0
  44. data/test/data/test_datetime.xls +0 -0
  45. data/test/data/test_empty.xls +0 -0
  46. data/test/data/test_formula.xls +0 -0
  47. data/test/data/test_long_sst_record.xls +0 -0
  48. data/test/data/test_missing_row.xls +0 -0
  49. data/test/data/test_version_excel5.xls +0 -0
  50. data/test/data/test_version_excel95.xls +0 -0
  51. data/test/data/test_version_excel97.xls +0 -0
  52. data/test/excel/row.rb +35 -0
  53. data/test/excel/writer/workbook.rb +23 -0
  54. data/test/excel/writer/worksheet.rb +24 -0
  55. data/test/font.rb +163 -0
  56. data/test/integration.rb +1311 -0
  57. data/test/row.rb +33 -0
  58. data/test/suite.rb +17 -0
  59. data/test/workbook.rb +29 -0
  60. data/test/worksheet.rb +80 -0
  61. metadata +118 -0
@@ -0,0 +1,402 @@
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
+ 0x0013 => :olive,
78
+ 0x0014 => :purple,
79
+ 0x0015 => :teal,
80
+ 0x0016 => :silver,
81
+ 0x0017 => :gray,
82
+ 0X0018 => :"#9999ff",
83
+ 0X0019 => :"#993366",
84
+ 0X001a => :"#ffffcc",
85
+ 0X001b => :"#ccffff",
86
+ 0X001c => :"#660066",
87
+ 0X001d => :"#ff8080",
88
+ 0X001e => :"#0066cc",
89
+ 0X001f => :"#ccccff",
90
+ 0X0020 => :"#000080",
91
+ 0X0021 => :"#ff00ff",
92
+ 0X0022 => :"#ffff00",
93
+ 0X0023 => :"#00ffff",
94
+ 0X0024 => :"#800080",
95
+ 0X0025 => :"#800000",
96
+ 0X0026 => :"#008080",
97
+ 0X0027 => :"#0000ff",
98
+ 0X0028 => :"#00ccff",
99
+ 0X0029 => :"#ccffff",
100
+ 0X002a => :"#ccffcc",
101
+ 0X002b => :"#ffff99",
102
+ 0X002c => :"#99ccff",
103
+ 0X002d => :"#ff99cc",
104
+ 0X002e => :"#cc99ff",
105
+ 0X002f => :"#ffcc99",
106
+ 0X0030 => :"#3366ff",
107
+ 0X0031 => :"#33cccc",
108
+ 0X0032 => :"#99cc00",
109
+ 0X0033 => :"#ffcc00",
110
+ 0X0034 => :"#ff9900",
111
+ 0X0035 => :"#ff6600",
112
+ 0X0036 => :"#666699",
113
+ 0X0037 => :"#969696",
114
+ 0X0038 => :"#003366",
115
+ 0X0039 => :"#339966",
116
+ 0X003a => :"#003300",
117
+ 0X003b => :"#333300",
118
+ 0X003c => :"#993300",
119
+ 0X003d => :"#993366",
120
+ 0X003e => :"#333399",
121
+ 0X003f => :"#333333",
122
+ 0x0040 => :border,
123
+ 0x0041 => :pattern_bg,
124
+ 0x0043 => :dialog_bg,
125
+ 0x004d => :chart_text,
126
+ 0x004e => :chart_bg,
127
+ 0x004f => :chart_border,
128
+ 0x0050 => :tooltip_bg,
129
+ 0x0051 => :tooltip_text,
130
+ 0x7fff => :text,
131
+ }
132
+ SEDOC_ROLOC = COLOR_CODES.invert.update( :aqua => 0x000f,
133
+ :fuchsia => 0x000e,
134
+ :grey => 0x0017 )
135
+ BINARY_FORMATS = {
136
+ :blank => 'v3',
137
+ :boolerr => 'v3C2',
138
+ :colinfo => 'v5x2',
139
+ :font => 'v5C3x',
140
+ :labelsst => 'v3V',
141
+ :number => "v3#{EIGHT_BYTE_DOUBLE}",
142
+ :pagesetup => "v8#{EIGHT_BYTE_DOUBLE}2v",
143
+ :rk => 'v3V',
144
+ :row => 'v4x4V',
145
+ :window2 => 'v4x2v2x4',
146
+ :xf => 'v3C4V2v',
147
+ }
148
+ # From BIFF5 on, the built-in number formats will be omitted. The built-in
149
+ # formats are dependent on the current regional settings of the operating
150
+ # system. The following table shows which number formats are used by
151
+ # default in a US-English environment. All indexes from 0 to 163 are
152
+ # reserved for built-in formats.
153
+ BUILTIN_FORMATS = { # TODO: locale support
154
+ 0 => 'GENERAL',
155
+ 1 => '0',
156
+ 2 => '0.00',
157
+ 3 => '#,##0',
158
+ 4 => '#,##0.00',
159
+ 5 => '"$"#,##0_);("$"#,##0)',
160
+ 6 => '"$"#,##0_);[Red]("$"#,##0)',
161
+ 7 => '"$"#,##0.00_);("$"#,##0.00)',
162
+ 8 => '"$"#,##0.00_);[Red]("$"#,##0.00)',
163
+ 9 => '0%',
164
+ 10 => '0.00%',
165
+ 11 => '0.00E+00',
166
+ 12 => '# ?/?',
167
+ 13 => '# ??/??',
168
+ 14 => 'M/D/YY',
169
+ 15 => 'D-MMM-YY',
170
+ 16 => 'D-MMM',
171
+ 17 => 'MMM-YY',
172
+ 18 => 'h:mm AM/PM',
173
+ 19 => 'h:mm:ss AM/PM',
174
+ 20 => 'h:mm',
175
+ 21 => 'h:mm:ss',
176
+ 22 => 'M/D/YY h:mm',
177
+ 37 => '_(#,##0_);(#,##0)',
178
+ 38 => '_(#,##0_);[Red](#,##0)',
179
+ 39 => '_(#,##0.00_);(#,##0.00)',
180
+ 40 => '_(#,##0.00_);[Red](#,##0.00)',
181
+ 41 => '_("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)',
182
+ 42 => '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',
183
+ 43 => '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)',
184
+ 44 => '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',
185
+ 45 => 'mm:ss',
186
+ 46 => '[h]:mm:ss',
187
+ 47 => 'mm:ss.0',
188
+ 48 => '##0.0E+0',
189
+ 49 => '@',
190
+ }
191
+ BUILTIN_STYLES = {
192
+ 0x00 => 'Normal',
193
+ 0x01 => 'RowLevel_lv',
194
+ 0x02 => 'ColLevel_lv',
195
+ 0x03 => 'Comma',
196
+ 0x04 => 'Currency',
197
+ 0x05 => 'Percent',
198
+ 0x06 => 'Comma',
199
+ 0x07 => 'Currency',
200
+ 0x08 => 'Hyperlink',
201
+ 0x09 => 'Followed Hyperlink',
202
+ }
203
+ ESCAPEMENT_TYPES = {
204
+ 0x0001 => :superscript,
205
+ 0x0002 => :subscript,
206
+ }
207
+ SEPYT_TNEMEPACSE = ESCAPEMENT_TYPES.invert
208
+ FONT_ENCODINGS = {
209
+ 0x00 => :iso_latin1,
210
+ 0x01 => :default,
211
+ 0x02 => :symbol,
212
+ 0x4d => :apple_roman,
213
+ 0x80 => :shift_jis,
214
+ 0x81 => :korean_hangul,
215
+ 0x82 => :korean_johab,
216
+ 0x86 => :chinese_simplified,
217
+ 0x88 => :chinese_traditional,
218
+ 0xa1 => :greek,
219
+ 0xa2 => :turkish,
220
+ 0xa3 => :vietnamese,
221
+ 0xb1 => :hebrew,
222
+ 0xb2 => :arabic,
223
+ 0xba => :baltic,
224
+ 0xcc => :cyrillic,
225
+ 0xde => :thai,
226
+ 0xee => :iso_latin2,
227
+ 0xff => :oem_latin1,
228
+ }
229
+ SGNIDOCNE_TNOF = FONT_ENCODINGS.invert
230
+ FONT_FAMILIES = {
231
+ 0x01 => :roman,
232
+ 0x02 => :swiss,
233
+ 0x03 => :modern,
234
+ 0x04 => :script,
235
+ 0x05 => :decorative,
236
+ }
237
+ SEILIMAF_TNOF = FONT_FAMILIES.invert
238
+ FONT_WEIGHTS = {
239
+ :bold => 700,
240
+ :normal => 400,
241
+ }
242
+ LEAP_ERROR = Date.new 1900, 2, 28
243
+ OPCODES = {
244
+ :blank => 0x0201, # BLANK ➜ 6.7
245
+ :boolerr => 0x0205, # BOOLERR ➜ 6.10
246
+ :boundsheet => 0x0085, # ●● BOUNDSHEET ➜ 6.12
247
+ :codepage => 0x0042, # ○ CODEPAGE ➜ 6.17
248
+ :colinfo => 0x007d, # ○○ COLINFO ➜ 6.18
249
+ :continue => 0x003c, # ○ CONTINUE ➜ 6.22
250
+ :datemode => 0x0022, # ○ DATEMODE ➜ 6.25
251
+ :dbcell => 0x0a0b, # ○ DBCELL
252
+ :dimensions => 0x0200, # ● DIMENSIONS ➜ 6.31
253
+ :eof => 0x000a, # ● EOF ➜ 6.36
254
+ :font => 0x0031, # ●● FONT ➜ 6.43
255
+ :format => 0x041e, # ○○ FORMAT (Number Format) ➜ 6.45
256
+ :formula => 0x0006, # FORMULA ➜ 6.46
257
+ :hlink => 0x01b8, # HLINK ➜ 6.52 (BIFF8 only)
258
+ :label => 0x0204, # LABEL ➜ 6.59 (BIFF2-BIFF7)
259
+ :labelsst => 0x00fd, # LABELSST ➜ 6.61 (BIFF8 only)
260
+ :mulblank => 0x00be, # MULBLANK ➜ 6.64 (BIFF5-BIFF8)
261
+ :mulrk => 0x00bd, # MULRK ➜ 6.65 (BIFF5-BIFF8)
262
+ :number => 0x0203, # NUMBER ➜ 6.68
263
+ :rk => 0x027e, # RK ➜ 6.82 (BIFF3-BIFF8)
264
+ :row => 0x0208, # ● ROW ➜ 6.83
265
+ :rstring => 0x00d6, # RSTRING ➜ 6.84 (BIFF5/BIFF7)
266
+ :sst => 0x00fc, # ● SST ➜ 6.96
267
+ :string => 0x0207, # STRING ➜ 6.98
268
+ :style => 0x0293, # ●● STYLE ➜ 6.99
269
+ :xf => 0x00e0, # ●● XF ➜ 6.115
270
+ :sharedfmla => 0x04bc, # SHAREDFMLA ➜ 5.94
271
+ ########################## Unhandled Opcodes ################################
272
+ :extsst => 0x00ff, # ● EXTSST ➜ 6.40
273
+ :index => 0x020b, # ○ INDEX ➜ 5.7 (Row Blocks), ➜ 6.55
274
+ :uncalced => 0x005e, # ○ UNCALCED ➜ 6.104
275
+ ########################## ○ Calculation Settings Block ➜ 5.3
276
+ :calccount => 0x000c, # ○ CALCCOUNT ➜ 6.14
277
+ :calcmode => 0x000d, # ○ CALCMODE ➜ 6.15
278
+ :precision => 0x000e, # ○ PRECISION ➜ 6.74 (moved to Workbook Globals
279
+ # Substream in BIFF5-BIFF8)
280
+ :refmode => 0x000f, # ○ REFMODE ➜ 6.80
281
+ :delta => 0x0010, # ○ DELTA ➜ 6.30
282
+ :iteration => 0x0011, # ○ ITERATION ➜ 6.57
283
+ :saverecalc => 0x005f, # ○ SAVERECALC ➜ 6.85 (BIFF3-BIFF8 only)
284
+ ########################## ○ Workbook Protection Block ➜ 5.18
285
+ :protect => 0x0012, # ○ PROTECT
286
+ # Worksheet contents: 1 = protected (➜ 6.77)
287
+ :windowprot => 0x0019, # ○ WINDOWPROTECT Window settings: 1 = protected
288
+ # (BIFF4W only, ➜ 6.110)
289
+ :objectprot => 0x0063, # ○ OBJECTPROTECT
290
+ # Embedded objects: 1 = protected (➜ 6.69)
291
+ :scenprotect => 0x00dd, # ○ SCENPROTECT
292
+ # Scenarios: 1 = protected (BIFF5-BIFF8, ➜ 6.86)
293
+ :password => 0x0013, # ○ PASSWORD Hash value of the password;
294
+ # 0 = no password (➜ 6.72)
295
+ ########################## ○ File Protection Block ➜ 5.19
296
+ :writeprot => 0x0086, # ○ WRITEPROT File is write protected
297
+ # (BIFF3-BIFF8, ➜ 6.112), password in FILESHARING
298
+ :filepass => 0x002f, # ○ FILEPASS File is read/write-protected,
299
+ # encryption information (➜ 6.41)
300
+ :writeaccess => 0x005c, # ○ WRITEACCESS User name (BIFF3-BIFF8, ➜ 6.111)
301
+ :filesharing => 0x005b, # ○ FILESHARING File sharing options
302
+ # (BIFF3-BIFF8, ➜ 6.42)
303
+ ########################## ○ Link Table ➜ 5.10.3
304
+ # ●● SUPBOOK Block(s)
305
+ # Settings for a referenced document
306
+ :supbook => 0x01ae, # ● SUPBOOK ➜ 6.100
307
+ :externname => 0x0223, # ○○ EXTERNNAME ➜ 6.38
308
+ :xct => 0x0059, # ○○ ● XCT ➜ 6.114
309
+ :crn => 0x005a, # ●● CRN ➜ 6.24
310
+ :externsheet => 0x0017, # ● EXTERNSHEET ➜ 6.39
311
+ :name => 0x0218, # ○○ NAME ➜ 6.66
312
+ ##########################
313
+ :window1 => 0x003d, # ● WINDOW1 ➜ 6.108 (has information on
314
+ # which Spreadsheet is 'active')
315
+ :backup => 0x0040, # ○ BACKUP ➜ 6.5
316
+ :country => 0x008c, # ○ COUNTRY (Make writeable?) ➜ 6.23
317
+ :hideobj => 0x008d, # ○ HIDEOBJ ➜ 6.52
318
+ :palette => 0x0092, # ○ PALETTE ➜ 6.70
319
+ :fngroupcnt => 0x009c, # ○ FNGROUPCOUNT
320
+ :bookbool => 0x00da, # ○ BOOKBOOL ➜ 6.9
321
+ :tabid => 0x013d, # ○ TABID
322
+ :useselfs => 0x0160, # ○ USESELFS (Natural Language Formulas) ➜ 6.105
323
+ :dsf => 0x0161, # ○ DSF (Double Stream File) ➜ 6.32
324
+ :refreshall => 0x01b7, # ○ REFRESHALL
325
+ ########################## ● Worksheet View Settings Block ➜ 5.5
326
+ :window2 => 0x023e, # ● WINDOW2 ➜ 5.110
327
+ :scl => 0x00a0, # ○ SCL ➜ 5.92 (BIFF4-BIFF8 only)
328
+ :pane => 0x0041, # ○ PANE ➜ 5.75
329
+ :selection => 0x001d, # ○○ SELECTION ➜ 5.93
330
+ ########################## ○ Page Settings Block ➜ 5.4
331
+ :hpagebreaks => 0x001b, # ○ HORIZONTALPAGEBREAKS ➜ 6.54
332
+ :vpagebreaks => 0x001a, # ○ VERTICALPAGEBREAKS ➜ 6.107
333
+ :header => 0x0014, # ○ HEADER ➜ 6.51
334
+ :footer => 0x0015, # ○ FOOTER ➜ 6.44
335
+ :hcenter => 0x0083, # ○ HCENTER ➜ 6.50 (BIFF3-BIFF8 only)
336
+ :vcenter => 0x0084, # ○ VCENTER ➜ 6.106 (BIFF3-BIFF8 only)
337
+ :leftmargin => 0x0026, # ○ LEFTMARGIN ➜ 6.62
338
+ :rightmargin => 0x0027, # ○ RIGHTMARGIN ➜ 6.81
339
+ :topmargin => 0x0028, # ○ TOPMARGIN ➜ 6.103
340
+ :bottommargin => 0x0029, # ○ BOTTOMMARGIN ➜ 6.11
341
+ # ○ PLS (opcode unknown)
342
+ :pagesetup => 0x00a1, # ○ PAGESETUP ➜ 6.89 (BIFF4-BIFF8 only)
343
+ :bitmap => 0x00e9, # ○ BITMAP ➜ 6.6 (Background-Bitmap, BIFF8 only)
344
+ ##########################
345
+ :printheaders => 0x002a, # ○ PRINTHEADERS ➜ 6.76
346
+ :printgridlns => 0x002b, # ○ PRINTGRIDLINES ➜ 6.75
347
+ :gridset => 0x0082, # ○ GRIDSET ➜ 6.48
348
+ :guts => 0x0080, # ○ GUTS ➜ 6.49
349
+ :defrowheight => 0x0225, # ○ DEFAULTROWHEIGHT ➜ 6.28
350
+ :wsbool => 0x0081, # ○ WSBOOL ➜ 6.113
351
+ :defcolwidth => 0x0055, # ○ DEFCOLWIDTH ➜ 6.29
352
+ :sort => 0x0090, # ○ SORT ➜ 6.95
353
+ }
354
+ =begin ## unknown opcodes
355
+ 0x00bf, 0x00c0, 0x00c1, 0x00e1, 0x00e2, 0x00eb, 0x01af, 0x01bc
356
+ =end
357
+ SEDOCPO = OPCODES.invert
358
+ TWIPS = 20
359
+ UNDERLINE_TYPES = {
360
+ 0x0001 => :single,
361
+ 0x0002 => :double,
362
+ 0x0021 => :single_accounting,
363
+ 0x0022 => :double_accounting,
364
+ }
365
+ SEPYT_ENILREDNU = UNDERLINE_TYPES.invert
366
+ XF_H_ALIGN = {
367
+ :default => 0,
368
+ :left => 1,
369
+ :center => 2,
370
+ :right => 3,
371
+ :fill => 4,
372
+ :justify => 5,
373
+ :merge => 6,
374
+ :distributed => 7,
375
+ }
376
+ NGILA_H_FX = XF_H_ALIGN.invert
377
+ XF_TEXT_DIRECTION = {
378
+ :context => 0,
379
+ :left_to_right => 1,
380
+ :right_to_left => 2,
381
+ }
382
+ NOITCERID_TXET_FX = XF_TEXT_DIRECTION.invert
383
+ XF_V_ALIGN = {
384
+ :top => 0,
385
+ :middle => 1,
386
+ :bottom => 2,
387
+ :justify => 3,
388
+ :distributed => 4,
389
+ }
390
+ NGILA_V_FX = XF_V_ALIGN.invert
391
+ OPCODE_SIZE = 4
392
+ ROW_HEIGHT = 12.1
393
+ SST_CHUNKSIZE = 20
394
+ def binfmt key
395
+ BINARY_FORMATS[key]
396
+ end
397
+ def opcode key
398
+ OPCODES[key]
399
+ end
400
+ end
401
+ end
402
+ end
@@ -0,0 +1,41 @@
1
+ require 'spreadsheet/compatibility'
2
+
3
+ module Spreadsheet
4
+ module Excel
5
+ ##
6
+ # This module is used to keep track of offsets in modified Excel documents.
7
+ # Considered internal and subject to change without notice.
8
+ module Offset
9
+ include Compatibility
10
+ attr_reader :changes, :offsets
11
+ def initialize *args
12
+ super
13
+ @changes = {}
14
+ @offsets = {}
15
+ end
16
+ def Offset.append_features mod
17
+ super
18
+ mod.module_eval do
19
+ class << self
20
+ include Compatibility
21
+ def offset *keys
22
+ keys.each do |key|
23
+ attr_reader key unless instance_methods.include? method_name(key)
24
+ define_method "#{key}=" do |value|
25
+ @changes.store key, true
26
+ instance_variable_set ivar_name(key), value
27
+ end
28
+ define_method "set_#{key}" do |value, pos, len|
29
+ instance_variable_set ivar_name(key), value
30
+ @offsets.store key, [pos, len]
31
+ havename = "have_set_#{key}"
32
+ send(havename, value, pos, len) if respond_to? havename
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ module Spreadsheet
2
+ module Excel
3
+ class Reader
4
+ ##
5
+ # This Module collects reader methods such as read_string that are specific to
6
+ # Biff5. This Module is likely to be expanded as Support for older Versions
7
+ # of Excel grows.
8
+ module Biff5
9
+ ##
10
+ # Read a String of 8-bit Characters
11
+ def read_string work, count_length=1
12
+ # Offset Size Contents
13
+ # 0 1 or 2 Length of the string (character count, ln)
14
+ # 1 or 2 ln Character array (8-bit characters)
15
+ fmt = count_length == 1 ? 'C' : 'v'
16
+ length, = work.unpack fmt
17
+ work[count_length, length]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,199 @@
1
+ module Spreadsheet
2
+ module Excel
3
+ class Reader
4
+ ##
5
+ # This Module collects reader methods such as read_string that are specific to
6
+ # Biff8. This Module is likely to be expanded as Support for older Versions
7
+ # of Excel grows and methods get moved here for disambiguation.
8
+ module Biff8
9
+ include Spreadsheet::Excel::Internals
10
+ ##
11
+ # When a String is too long for one Opcode, it is continued in a Continue
12
+ # Opcode. Excel may reconsider compressing the remainder of the string.
13
+ # This method appends the available remainder (decompressed if necessary) to
14
+ # the incomplete string.
15
+ def continue_string work, incomplete_string=@incomplete_string
16
+ opts, _ = work.unpack 'C'
17
+ wide = opts & 1
18
+ head, chars = incomplete_string
19
+ owing = chars - head.size / 2
20
+ size = owing * (wide + 1)
21
+ string = work[1, size]
22
+ if wide == 0
23
+ string = wide string
24
+ end
25
+ head << string
26
+ if head.size >= chars * 2
27
+ @incomplete_string = nil
28
+ end
29
+ size + 1
30
+ end
31
+ ##
32
+ # When a String is too long for one Opcode, it is continued in a Continue
33
+ # Opcode. Excel may reconsider compressing the remainder of the string.
34
+ # This method only evaluates the header and registers the address of the
35
+ # continuation with the previous SstEntry.
36
+ def continue_string_header work, oppos
37
+ opts, _ = work.unpack 'C'
38
+ wide = opts & 1
39
+ owing = @incomplete_sst.continued_chars
40
+ size = [work.size, owing * (1 + wide) + 1].min
41
+ chars = (size - 1) / (1 + wide)
42
+ skip = size
43
+ @incomplete_sst.continue oppos + OPCODE_SIZE, size, chars
44
+ unless @incomplete_sst.continued?
45
+ @workbook.add_shared_string @incomplete_sst
46
+ skip += @incomplete_skip
47
+ @incomplete_sst = nil
48
+ @incomplete_skip = nil
49
+ end
50
+ skip
51
+ end
52
+ ##
53
+ # Read more data into the Shared String Table. (see also: #read_sst)
54
+ # This method only evaluates the header, the actual work is done in #_read_sst
55
+ def continue_sst work, oppos, len
56
+ pos = 0
57
+ if @incomplete_sst
58
+ pos = continue_string_header work, oppos
59
+ elsif !@incomplete_skip.nil?
60
+ pos = @incomplete_skip
61
+ @incomplete_skip = nil
62
+ end
63
+ @sst_offset[1] += len
64
+ _read_sst work, oppos, pos
65
+ end
66
+ def postread_workbook # :nodoc:
67
+ super
68
+ @incomplete_string, @sst_size, @sst_offset, @incomplete_sst = nil, @incomplete_skip = nil
69
+ end
70
+ ##
71
+ # Store the offset of extsst, so we can write a new extsst when the
72
+ # sst has changed
73
+ def read_extsst work, pos, len
74
+ @workbook.offsets.store :extsst, [pos, len]
75
+ end
76
+ ##
77
+ # Read the Shared String Table present in all Biff8 Files.
78
+ # This method only evaluates the header, the actual work is done in #_read_sst
79
+ def read_sst work, pos, len
80
+ # Offset Size Contents
81
+ # 0 4 Total number of strings in the workbook (see below)
82
+ # 4 4 Number of following strings (nm)
83
+ # 8 var. List of nm Unicode strings, 16-bit string length (➜ 3.4)
84
+ total, @sst_size = work.unpack 'V2'
85
+ @sst_offset = [pos, len]
86
+ @workbook.offsets.store :sst, @sst_offset
87
+ _read_sst work, pos, 8
88
+ end
89
+ ##
90
+ # Read a string from the Spreadsheet, such as a Worksheet- or Font-Name, or a
91
+ # Number-Format. See also #read_string_header and #read_string_body
92
+ def read_string work, count_length=1
93
+ # Offset Size Contents
94
+ # 0 1 or 2 Length of the string (character count, ln)
95
+ # 1 or 2 1 Option flags:
96
+ # Bit Mask Contents
97
+ # 0 0x01 Character compression (ccompr):
98
+ # 0 = Compressed (8-bit characters)
99
+ # 1 = Uncompressed (16-bit characters)
100
+ # 2 0x04 Asian phonetic settings (phonetic):
101
+ # 0 = Does not contain Asian phonetic settings
102
+ # 1 = Contains Asian phonetic settings
103
+ # 3 0x08 Rich-Text settings (richtext):
104
+ # 0 = Does not contain Rich-Text settings
105
+ # 1 = Contains Rich-Text settings
106
+ # [2 or 3] 2 (optional, only if richtext=1)
107
+ # Number of Rich-Text formatting runs (rt)
108
+ # [var.] 4 (optional, only if phonetic=1)
109
+ # Size of Asian phonetic settings block (in bytes, sz)
110
+ # var. ln Character array (8-bit characters
111
+ # or 2∙ln or 16-bit characters, dependent on ccompr)
112
+ # [var.] 4∙rt (optional, only if richtext=1)
113
+ # List of rt formatting runs (➜ 3.2)
114
+ # [var.] sz (optional, only if phonetic=1)
115
+ # Asian Phonetic Settings Block (➜ 3.4.2)
116
+ chars, offset, wide, phonetic, richtext, available, owing, skip \
117
+ = read_string_header work, count_length
118
+ string, data = read_string_body work, offset, available, wide > 0
119
+ if owing > 0
120
+ @incomplete_string = [string, chars]
121
+ end
122
+ string
123
+ end
124
+ ##
125
+ # Read the body of a string. Returns the String (decompressed if necessary) and
126
+ # the available data (unchanged).
127
+ def read_string_body work, offset, available, wide
128
+ data = work[offset, available]
129
+ string = wide ? data : wide(data)
130
+ [string, data]
131
+ end
132
+ ##
133
+ # Read the header of a string. Returns the following information in an Array:
134
+ # * The total number of characters in the string
135
+ # * The offset of the actual string data (= the length of this header in bytes)
136
+ # * Whether or not the string was compressed (0/1)
137
+ # * Whether or not the string contains asian phonetic settings (0/1)
138
+ # * Whether or not the string contains richtext formatting (0/1)
139
+ # * The number of bytes containing characters in this chunk of data
140
+ # * The number of characters missing from this chunk of data and expected to
141
+ # follow in a Continue Opcode
142
+ def read_string_header work, count_length=1, offset=0
143
+ fmt = count_length == 1 ? 'C2' : 'vC'
144
+ chars, opts = work[offset, 1 + count_length].unpack fmt
145
+ wide = opts & 1
146
+ phonetic = (opts >> 2) & 1
147
+ richtext = (opts >> 3) & 1
148
+ size = chars * (wide + 1)
149
+ skip = 0
150
+ if richtext > 0
151
+ runs, = work[offset + 1 + count_length, 2].unpack 'v'
152
+ skip = 4 * runs
153
+ end
154
+ if phonetic > 0
155
+ psize, = work[offset + 1 + count_length + richtext * 2, 4].unpack 'V'
156
+ skip += psize
157
+ end
158
+ flagsize = 1 + count_length + richtext * 2 + phonetic * 4
159
+ avbl = [work.size - offset, flagsize + size].min
160
+ have_chrs = (avbl - flagsize) / (1 + wide)
161
+ owing = chars - have_chrs
162
+ [chars, flagsize, wide, phonetic, richtext, avbl, owing, skip]
163
+ end
164
+ ##
165
+ # Insert null-characters into a compressed UTF-16 string
166
+ def wide string
167
+ data = ''
168
+ string.each_byte do |byte| data << byte.chr << 0.chr end
169
+ data
170
+ end
171
+ private
172
+ ##
173
+ # Read the Shared String Table present in all Biff8 Files.
174
+ def _read_sst work, oppos, pos
175
+ worksize = work.size
176
+ while @workbook.sst_size < @sst_size && pos < worksize do
177
+ sst = SstEntry.new :offset => oppos + OPCODE_SIZE + pos,
178
+ :ole => @data,
179
+ :reader => self
180
+ sst.chars, sst.flags, wide, sst.phonetic, sst.richtext, sst.available,
181
+ sst.continued_chars, skip = read_string_header work, 2, pos
182
+ sst.wide = wide > 0
183
+ if sst.continued?
184
+ @incomplete_sst = sst
185
+ @incomplete_skip = skip
186
+ pos += sst.available
187
+ else
188
+ @workbook.add_shared_string sst
189
+ pos += sst.available + skip
190
+ if pos > worksize
191
+ @incomplete_skip = pos - worksize
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end