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,115 +1,134 @@
1
- require 'spreadsheet/excel/offset'
2
- require 'spreadsheet/excel/row'
3
- require 'spreadsheet/worksheet'
1
+ require "spreadsheet/excel/offset"
2
+ require "spreadsheet/excel/row"
3
+ require "spreadsheet/worksheet"
4
4
 
5
5
  module Spreadsheet
6
6
  module Excel
7
- ##
8
- # Excel-specific Worksheet methods. These are mostly pertinent to the Excel
9
- # reader, and to recording changes to the Worksheet. You should have no reason
10
- # to use any of these.
11
- class Worksheet < Spreadsheet::Worksheet
12
- include Spreadsheet::Excel::Offset
13
- offset :dimensions
14
- attr_reader :offset, :ole, :links, :guts, :notes
15
- def initialize opts = {}
16
- @row_addresses = nil
17
- super
18
- @offset, @ole, @reader = opts[:offset], opts[:ole], opts[:reader]
19
- @dimensions = nil
20
- @links = {}
21
- @guts = {}
22
- @notes = {}
23
- end
24
- def add_link row, column, link
25
- @links.store [row, column], link
26
- end
27
- def add_note row, column, note
28
- @notes.store [row, column], note
29
- end
30
- def column idx
31
- ensure_rows_read
32
- super
33
- end
34
- def date_base
35
- @workbook.date_base
36
- end
37
- def margins
38
- ensure_rows_read
39
- super
40
- end
41
- def pagesetup
42
- ensure_rows_read
43
- super
44
- end
45
- def each *args
46
- ensure_rows_read
47
- super
48
- end
49
- def ensure_rows_read
50
- return if @row_addresses
51
- @dimensions = nil
52
- @row_addresses = []
53
- @reader.read_worksheet self, @offset if @reader
54
- end
55
- def row idx
56
- @rows[idx] or begin
57
- ensure_rows_read
58
- if addr = @row_addresses[idx]
59
- row = @reader.read_row self, addr
60
- [:default_format, :height, :outline_level, :hidden, ].each do |key|
61
- row.send "unupdated_#{key}=", addr[key]
7
+ ##
8
+ # Excel-specific Worksheet methods. These are mostly pertinent to the Excel
9
+ # reader, and to recording changes to the Worksheet. You should have no reason
10
+ # to use any of these.
11
+ class Worksheet < Spreadsheet::Worksheet
12
+ include Spreadsheet::Excel::Offset
13
+
14
+ offset :dimensions
15
+ attr_reader :offset, :ole, :links, :guts, :notes, :row_addresses
16
+ def initialize opts = {}
17
+ @row_addresses = nil
18
+ super
19
+ @offset, @ole, @reader = opts[:offset], opts[:ole], opts[:reader]
20
+ @dimensions = nil
21
+ @links = {}
22
+ @guts = {}
23
+ @notes = {}
24
+ end
25
+
26
+ def add_link row, column, link
27
+ @links.store [row, column], link
28
+ end
29
+
30
+ def add_note row, column, note
31
+ @notes.store [row, column], note
32
+ end
33
+
34
+ def column idx
35
+ ensure_rows_read
36
+ super
37
+ end
38
+
39
+ def date_base
40
+ @workbook.date_base
41
+ end
42
+
43
+ def margins
44
+ ensure_rows_read
45
+ super
46
+ end
47
+
48
+ def pagesetup
49
+ ensure_rows_read
50
+ super
51
+ end
52
+
53
+ def each *args
54
+ ensure_rows_read
55
+ super
56
+ end
57
+
58
+ def ensure_rows_read
59
+ return if @row_addresses
60
+ @dimensions = nil
61
+ @row_addresses = []
62
+ @reader&.read_worksheet self, @offset
63
+ end
64
+
65
+ def row idx
66
+ @rows[idx] or begin
67
+ ensure_rows_read
68
+ if (addr = @row_addresses[idx])
69
+ row = @reader.read_row self, addr
70
+ [:default_format, :height, :outline_level, :hidden].each do |key|
71
+ row.send :"unupdated_#{key}=", addr[key]
72
+ end
73
+ row.worksheet = self
74
+ row
75
+ else
76
+ Row.new self, idx
77
+ end
62
78
  end
63
- row.worksheet = self
64
- row
65
- else
66
- Row.new self, idx
79
+ end
80
+
81
+ def rows
82
+ to_a
83
+ end
84
+
85
+ def row_updated idx, row
86
+ res = super
87
+ @workbook.changes.store self, true
88
+ @workbook.changes.store :boundsheets, true
89
+ @changes.store idx, true
90
+ @changes.store :dimensions, true
91
+ res
92
+ end
93
+
94
+ def set_row_address idx, opts
95
+ @offsets.store idx, opts[:row_block]
96
+ @row_addresses[idx] = opts
97
+ end
98
+
99
+ def shared_string idx
100
+ @workbook.shared_string idx
101
+ end
102
+
103
+ private
104
+
105
+ ## premature optimization?
106
+ def have_set_dimensions value, pos, len
107
+ if @row_addresses.size < row_count
108
+ @row_addresses.concat Array.new(row_count - @row_addresses.size)
109
+ end
110
+ end
111
+
112
+ def recalculate_dimensions
113
+ ensure_rows_read
114
+ shorten @rows
115
+ @dimensions = []
116
+ @dimensions[0] = [index_of_first(@rows),
117
+ index_of_first(@row_addresses)].compact.min || 0
118
+ @dimensions[1] = [@rows.size, @row_addresses.size].compact.max || 0
119
+ compact = @rows.compact
120
+ first_rows = compact.collect { |row| row.first_used }.compact.min
121
+ first_addrs = @row_addresses.compact.collect do |addr|
122
+ addr[:first_used]
123
+ end.compact.min
124
+ @dimensions[2] = [first_rows, first_addrs].compact.min || 0
125
+ last_rows = compact.collect { |row| row.first_unused }.max
126
+ last_addrs = @row_addresses.compact.collect do |addr|
127
+ addr[:first_unused]
128
+ end.compact.max
129
+ @dimensions[3] = [last_rows, last_addrs].compact.max || 0
130
+ @dimensions
67
131
  end
68
132
  end
69
133
  end
70
- def rows
71
- self.to_a
72
- end
73
- def row_updated idx, row
74
- res = super
75
- @workbook.changes.store self, true
76
- @workbook.changes.store :boundsheets, true
77
- @changes.store idx, true
78
- @changes.store :dimensions, true
79
- res
80
- end
81
- def set_row_address idx, opts
82
- @offsets.store idx, opts[:row_block]
83
- @row_addresses[idx] = opts
84
- end
85
- def shared_string idx
86
- @workbook.shared_string idx
87
- end
88
- private
89
- ## premature optimization?
90
- def have_set_dimensions value, pos, len
91
- if @row_addresses.size < row_count
92
- @row_addresses.concat Array.new(row_count - @row_addresses.size)
93
- end
94
- end
95
- def recalculate_dimensions
96
- ensure_rows_read
97
- shorten @rows
98
- @dimensions = []
99
- @dimensions[0] = [ index_of_first(@rows),
100
- index_of_first(@row_addresses) ].compact.min || 0
101
- @dimensions[1] = [ @rows.size, @row_addresses.size ].compact.max || 0
102
- compact = @rows.compact
103
- first_rows = compact.collect do |row| row.first_used end.compact.min
104
- first_addrs = @row_addresses.compact.collect do |addr|
105
- addr[:first_used] end.compact.min
106
- @dimensions[2] = [ first_rows, first_addrs ].compact.min || 0
107
- last_rows = compact.collect do |row| row.first_unused end.max
108
- last_addrs = @row_addresses.compact.collect do |addr|
109
- addr[:first_unused] end.compact.max
110
- @dimensions[3] = [last_rows, last_addrs].compact.max || 0
111
- @dimensions
112
- end
113
- end
114
- end
115
134
  end
@@ -1,53 +1,55 @@
1
- require 'spreadsheet/encodings'
1
+ require "spreadsheet/encodings"
2
2
 
3
3
  module Spreadsheet
4
4
  module Excel
5
5
  module Writer
6
- ##
7
- # This Module collects writer methods such as unicode_string that are specific
8
- # to Biff8. This Module is likely to be expanded as Support for older Versions
9
- # of Excel grows and methods get moved here for disambiguation.
10
- module Biff8
11
- include Spreadsheet::Encodings
12
- ##
13
- # Check whether the string _data_ can be compressed (i.e. every second byte
14
- # is a Null-byte) and perform compression.
15
- # Returns the data and compression_status (0/1)
16
- def compress_unicode_string data
17
- compressed = internal('')
18
- expect_null = false
19
- data.each_byte do |byte|
20
- if expect_null
21
- if byte != 0
22
- return [data, 1] # 1 => Data consists of wide Chars
6
+ ##
7
+ # This Module collects writer methods such as unicode_string that are specific
8
+ # to Biff8. This Module is likely to be expanded as Support for older Versions
9
+ # of Excel grows and methods get moved here for disambiguation.
10
+ module Biff8
11
+ include Spreadsheet::Encodings
12
+
13
+ ##
14
+ # Check whether the string _data_ can be compressed (i.e. every second byte
15
+ # is a Null-byte) and perform compression.
16
+ # Returns the data and compression_status (0/1)
17
+ def compress_unicode_string data
18
+ compressed = internal("")
19
+ expect_null = false
20
+ data.each_byte do |byte|
21
+ if expect_null
22
+ if byte != 0
23
+ return [data, 1] # 1 => Data consists of wide Chars
24
+ end
25
+ expect_null = false
26
+ else
27
+ compressed << byte
28
+ expect_null = true
29
+ end
30
+ end
31
+ [compressed, 0] # 0 => Data consists of compressed Chars
23
32
  end
24
- expect_null = false
25
- else
26
- compressed << byte
27
- expect_null = true
28
- end
29
- end
30
- [compressed, 0] # 0 => Data consists of compressed Chars
31
- end
32
- ##
33
- # Encode _string_ into a Biff8 Unicode String. Header and body are encoded
34
- # separately by #_unicode_string. This method simply combines the two.
35
- def unicode_string string, count_length=1
36
- header, data, _ = _unicode_string string, count_length
37
- header << data
38
- end
39
- @@bytesize = RUBY_VERSION >= '1.9' ? :bytesize : :size
40
- ##
41
- # Encode _string_ into a Biff8 Unicode String Header and Body.
42
- def _unicode_string string, count_length=1
43
- data = internal string
44
- size = data.send(@@bytesize) / 2
45
- fmt = count_length == 1 ? 'C2' : 'vC'
46
- data, wide = compress_unicode_string data
47
- opts = wide
48
- header = [
49
- size, # Length of the string (character count, ln)
50
- opts, # Option flags:
33
+
34
+ ##
35
+ # Encode _string_ into a Biff8 Unicode String. Header and body are encoded
36
+ # separately by #_unicode_string. This method simply combines the two.
37
+ def unicode_string string, count_length = 1
38
+ header, data, _ = _unicode_string string, count_length
39
+ header << data
40
+ end
41
+ @@bytesize = (RUBY_VERSION >= "1.9") ? :bytesize : :size
42
+ ##
43
+ # Encode _string_ into a Biff8 Unicode String Header and Body.
44
+ def _unicode_string string, count_length = 1
45
+ data = internal string
46
+ size = data.send(@@bytesize) / 2
47
+ fmt = (count_length == 1) ? "C2" : "vC"
48
+ data, wide = compress_unicode_string data
49
+ opts = wide
50
+ header = [
51
+ size, # Length of the string (character count, ln)
52
+ opts # Option flags:
51
53
  # Bit Mask Contents
52
54
  # 0 0x01 Character compression (ccompr):
53
55
  # 0 = Compressed (8-bit characters)
@@ -58,18 +60,18 @@ module Biff8
58
60
  # 3 0x08 Rich-Text settings (richtext):
59
61
  # 0 = Does not contain Rich-Text settings
60
62
  # 1 = Contains Rich-Text settings
61
- #0x00,# (optional, only if richtext=1) Number of Rich-Text
63
+ # 0x00,# (optional, only if richtext=1) Number of Rich-Text
62
64
  # formatting runs (rt)
63
- #0x00,# (optional, only if phonetic=1) Size of Asian phonetic
65
+ # 0x00,# (optional, only if phonetic=1) Size of Asian phonetic
64
66
  # settings block (in bytes, sz)
65
- ].pack fmt
66
- data << '' # (optional, only if richtext=1)
67
- # List of rt formatting runs (➜ 3.2)
68
- data << '' # (optional, only if phonetic=1)
69
- # Asian Phonetic Settings Block (➜ 3.4.2)
70
- [header, data, wide]
71
- end
72
- end
67
+ ].pack fmt
68
+ data << "" # (optional, only if richtext=1)
69
+ # List of rt formatting runs (➜ 3.2)
70
+ data << "" # (optional, only if phonetic=1)
71
+ # Asian Phonetic Settings Block (➜ 3.4.2)
72
+ [header, data, wide]
73
+ end
74
+ end
73
75
  end
74
76
  end
75
77
  end