spreadsheet 1.3.2 → 1.3.4

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parseexcel/parseexcel.rb +66 -58
  3. data/lib/parseexcel/parser.rb +1 -1
  4. data/lib/parseexcel.rb +1 -1
  5. data/lib/spreadsheet/column.rb +11 -9
  6. data/lib/spreadsheet/compatibility.rb +3 -1
  7. data/lib/spreadsheet/datatypes.rb +149 -147
  8. data/lib/spreadsheet/encodings.rb +20 -16
  9. data/lib/spreadsheet/errors.rb +2 -2
  10. data/lib/spreadsheet/excel/error.rb +23 -22
  11. data/lib/spreadsheet/excel/internals/biff5.rb +11 -11
  12. data/lib/spreadsheet/excel/internals/biff8.rb +13 -13
  13. data/lib/spreadsheet/excel/internals.rb +451 -451
  14. data/lib/spreadsheet/excel/offset.rb +32 -31
  15. data/lib/spreadsheet/excel/password_hash.rb +18 -18
  16. data/lib/spreadsheet/excel/reader/biff5.rb +34 -35
  17. data/lib/spreadsheet/excel/reader/biff8.rb +234 -222
  18. data/lib/spreadsheet/excel/reader.rb +1320 -1274
  19. data/lib/spreadsheet/excel/rgb.rb +91 -91
  20. data/lib/spreadsheet/excel/row.rb +99 -91
  21. data/lib/spreadsheet/excel/sst_entry.rb +40 -38
  22. data/lib/spreadsheet/excel/workbook.rb +86 -76
  23. data/lib/spreadsheet/excel/worksheet.rb +125 -107
  24. data/lib/spreadsheet/excel/writer/biff8.rb +56 -55
  25. data/lib/spreadsheet/excel/writer/format.rb +273 -256
  26. data/lib/spreadsheet/excel/writer/n_worksheet.rb +837 -798
  27. data/lib/spreadsheet/excel/writer/workbook.rb +671 -635
  28. data/lib/spreadsheet/excel/writer/worksheet.rb +898 -861
  29. data/lib/spreadsheet/excel/writer.rb +1 -1
  30. data/lib/spreadsheet/excel.rb +18 -11
  31. data/lib/spreadsheet/font.rb +30 -26
  32. data/lib/spreadsheet/format.rb +74 -59
  33. data/lib/spreadsheet/link.rb +7 -5
  34. data/lib/spreadsheet/note.rb +6 -6
  35. data/lib/spreadsheet/noteObject.rb +5 -5
  36. data/lib/spreadsheet/row.rb +33 -23
  37. data/lib/spreadsheet/version.rb +1 -1
  38. data/lib/spreadsheet/workbook.rb +27 -13
  39. data/lib/spreadsheet/worksheet.rb +102 -68
  40. data/lib/spreadsheet/writer.rb +3 -0
  41. data/lib/spreadsheet.rb +12 -15
  42. data/test/excel/reader.rb +8 -8
  43. data/test/excel/row.rb +35 -31
  44. data/test/excel/writer/workbook.rb +18 -16
  45. data/test/excel/writer/worksheet.rb +10 -8
  46. data/test/font.rb +44 -32
  47. data/test/format.rb +38 -33
  48. data/test/integration.rb +627 -598
  49. data/test/row.rb +5 -3
  50. data/test/suite.rb +7 -7
  51. data/test/workbook.rb +15 -14
  52. data/test/workbook_protection.rb +5 -5
  53. data/test/worksheet.rb +36 -34
  54. metadata +50 -8
data/test/integration.rb CHANGED
@@ -1,46 +1,49 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+
3
3
  # TestIntegration -- spreadheet -- 07.09.2011 -- mhatakeyama@ywesee.com
4
4
  # TestIntegration -- spreadheet -- 08.10.2007 -- hwyss@ywesee.com
5
5
 
6
- $: << File.expand_path('../lib', File.dirname(__FILE__))
6
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
7
7
 
8
- require 'test/unit'
9
- require 'spreadsheet'
10
- require 'fileutils'
8
+ require "test/unit"
9
+ require "spreadsheet"
10
+ require "fileutils"
11
11
 
12
12
  module Spreadsheet
13
13
  class TestIntegration < Test::Unit::TestCase
14
- if RUBY_VERSION >= '1.9'
14
+ if RUBY_VERSION >= "1.9"
15
15
  class IconvStub
16
16
  def initialize to, from
17
17
  @to, @from = to, from
18
18
  end
19
+
19
20
  def iconv str
20
21
  dp = str.dup
21
22
  dp.force_encoding @from
22
23
  dp.encode @to
23
24
  end
24
25
  end
25
- @@iconv = IconvStub.new('UTF-16LE', 'UTF-8')
26
+ @@iconv = IconvStub.new("UTF-16LE", "UTF-8")
26
27
  @@bytesize = :bytesize
27
28
  else
28
- @@iconv = Iconv.new('UTF-16LE', 'UTF-8')
29
+ @@iconv = Iconv.new("UTF-16LE", "UTF-8")
29
30
  @@bytesize = :size
30
31
  end
31
32
  def setup
32
- @var = File.expand_path 'var', File.dirname(__FILE__)
33
+ @var = File.expand_path "var", File.dirname(__FILE__)
33
34
  FileUtils.mkdir_p @var
34
- @data = File.expand_path 'data', File.dirname(__FILE__)
35
+ @data = File.expand_path "data", File.dirname(__FILE__)
35
36
  FileUtils.mkdir_p @data
36
37
  end
38
+
37
39
  def teardown
38
- Spreadsheet.client_encoding = 'UTF-8'
40
+ Spreadsheet.client_encoding = "UTF-8"
39
41
  FileUtils.rm_rf @var
40
42
  end
43
+
41
44
  def test_copy__identical__file_paths
42
- path = File.join @data, 'test_copy.xls'
43
- copy = File.join @data, 'test_copy1.xls'
45
+ path = File.join @data, "test_copy.xls"
46
+ copy = File.join @data, "test_copy1.xls"
44
47
  book = Spreadsheet.open path
45
48
  assert_instance_of Excel::Workbook, book
46
49
  book.write copy
@@ -48,13 +51,14 @@ module Spreadsheet
48
51
  ensure
49
52
  File.delete copy if File.exist? copy
50
53
  end
54
+
51
55
  def test_empty_workbook
52
- path = File.join @data, 'test_empty.xls'
56
+ path = File.join @data, "test_empty.xls"
53
57
  book = Spreadsheet.open path
54
58
  assert_instance_of Excel::Workbook, book
55
59
  assert_equal 8, book.biff_version
56
- assert_equal 'Microsoft Excel 97/2000/XP', book.version_string
57
- enc = 'UTF-16LE'
60
+ assert_equal "Microsoft Excel 97/2000/XP", book.version_string
61
+ enc = "UTF-16LE"
58
62
  if defined? Encoding
59
63
  enc = Encoding.find enc
60
64
  end
@@ -65,24 +69,26 @@ module Spreadsheet
65
69
  sheet = book.worksheet 0
66
70
  assert_equal 0, sheet.row_count
67
71
  assert_equal 0, sheet.column_count
68
- assert_nothing_raised do sheet.inspect end
72
+ assert_nothing_raised { sheet.inspect }
69
73
  end
74
+
70
75
  def test_missing_format
71
- path = File.join @data, 'test_missing_format.xls'
76
+ path = File.join @data, "test_missing_format.xls"
72
77
  assert_nothing_thrown do
73
78
  Spreadsheet.open(path, "rb")
74
79
  end
75
80
  end
81
+
76
82
  def test_version_excel97__excel2010__utf16
77
- Spreadsheet.client_encoding = 'UTF-16LE'
78
- assert_equal 'UTF-16LE', Spreadsheet.client_encoding
79
- path = File.join @data, 'test_version_excel97_2010.xls'
83
+ Spreadsheet.client_encoding = "UTF-16LE"
84
+ assert_equal "UTF-16LE", Spreadsheet.client_encoding
85
+ path = File.join @data, "test_version_excel97_2010.xls"
80
86
  book = Spreadsheet.open path
81
87
  assert_instance_of Excel::Workbook, book
82
88
  assert_equal 8, book.biff_version
83
- assert_equal @@iconv.iconv('Microsoft Excel 97/2000/XP'),
84
- book.version_string
85
- enc = 'UTF-16LE'
89
+ assert_equal @@iconv.iconv("Microsoft Excel 97/2000/XP"),
90
+ book.version_string
91
+ enc = "UTF-16LE"
86
92
  if defined? Encoding
87
93
  enc = Encoding.find enc
88
94
  end
@@ -92,36 +98,37 @@ module Spreadsheet
92
98
  assert_equal 0.00009, row[0]
93
99
  link = row[1]
94
100
  assert_instance_of Link, link
95
- assert_equal @@iconv.iconv('Link-Text'), link
96
- assert_equal @@iconv.iconv('http://scm.ywesee.com/spreadsheet'), link.url
97
- assert_equal @@iconv.iconv('http://scm.ywesee.com/spreadsheet'), link.href
101
+ assert_equal @@iconv.iconv("Link-Text"), link
102
+ assert_equal @@iconv.iconv("http://scm.ywesee.com/spreadsheet"), link.url
103
+ assert_equal @@iconv.iconv("http://scm.ywesee.com/spreadsheet"), link.href
98
104
  end
105
+
99
106
  def test_version_excel97__ooffice__utf16
100
- Spreadsheet.client_encoding = 'UTF-16LE'
101
- assert_equal 'UTF-16LE', Spreadsheet.client_encoding
102
- path = File.join @data, 'test_version_excel97.xls'
107
+ Spreadsheet.client_encoding = "UTF-16LE"
108
+ assert_equal "UTF-16LE", Spreadsheet.client_encoding
109
+ path = File.join @data, "test_version_excel97.xls"
103
110
  book = Spreadsheet.open path
104
111
  assert_instance_of Excel::Workbook, book
105
112
  assert_equal 8, book.biff_version
106
- assert_equal @@iconv.iconv('Microsoft Excel 97/2000/XP'),
107
- book.version_string
108
- enc = 'UTF-16LE'
113
+ assert_equal @@iconv.iconv("Microsoft Excel 97/2000/XP"),
114
+ book.version_string
115
+ enc = "UTF-16LE"
109
116
  if defined? Encoding
110
117
  enc = Encoding.find enc
111
118
  end
112
119
  assert_equal enc, book.encoding
113
120
  assert_equal 25, book.formats.size
114
121
  assert_equal 5, book.fonts.size
115
- str1 = @@iconv.iconv('Shared String')
116
- str2 = @@iconv.iconv('Another Shared String')
117
- str3 = @@iconv.iconv('1234567890 ' * 1000)
118
- str4 = @@iconv.iconv('9876543210 ' * 1000)
119
- assert_valid_sst(book, :contains => [str1, str2, str3, str4])
122
+ str1 = @@iconv.iconv("Shared String")
123
+ str2 = @@iconv.iconv("Another Shared String")
124
+ str3 = @@iconv.iconv("1234567890 " * 1000)
125
+ str4 = @@iconv.iconv("9876543210 " * 1000)
126
+ assert_valid_sst(book, contains: [str1, str2, str3, str4])
120
127
  sheet = book.worksheet 0
121
128
  assert_equal 11, sheet.row_count
122
129
  assert_equal 12, sheet.column_count
123
- useds = [0,0,0,0,0,0,0,1,0,0,11]
124
- unuseds = [2,2,1,1,1,2,1,11,1,2,12]
130
+ useds = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 11]
131
+ unuseds = [2, 2, 1, 1, 1, 2, 1, 11, 1, 2, 12]
125
132
  sheet.each do |row|
126
133
  assert_equal useds.shift, row.first_used
127
134
  assert_equal unuseds.shift, row.first_unused
@@ -129,82 +136,83 @@ module Spreadsheet
129
136
  assert unuseds.empty?, "not all rows were visited in Spreadsheet#each"
130
137
  row = sheet.row 0
131
138
  assert_equal str1, row[0]
132
- assert_equal str1, sheet[0,0]
133
- assert_equal str1, sheet.cell(0,0)
139
+ assert_equal str1, sheet[0, 0]
140
+ assert_equal str1, sheet.cell(0, 0)
134
141
  assert_equal str1, row[1]
135
- assert_equal str1, sheet[0,1]
136
- assert_equal str1, sheet.cell(0,1)
142
+ assert_equal str1, sheet[0, 1]
143
+ assert_equal str1, sheet.cell(0, 1)
137
144
  row = sheet.row 1
138
145
  assert_equal str2, row[0]
139
- assert_equal str2, sheet[1,0]
140
- assert_equal str2, sheet.cell(1,0)
146
+ assert_equal str2, sheet[1, 0]
147
+ assert_equal str2, sheet.cell(1, 0)
141
148
  assert_equal str2, row[1]
142
- assert_equal str2, sheet[1,1]
143
- assert_equal str2, sheet.cell(1,1)
149
+ assert_equal str2, sheet[1, 1]
150
+ assert_equal str2, sheet.cell(1, 1)
144
151
  row = sheet.row 2
145
152
  assert_equal str3, row[0]
146
- assert_equal str3, sheet[2,0]
147
- assert_equal str3, sheet.cell(2,0)
153
+ assert_equal str3, sheet[2, 0]
154
+ assert_equal str3, sheet.cell(2, 0)
148
155
  assert_nil row[1]
149
- assert_nil sheet[2,1]
150
- assert_nil sheet.cell(2,1)
156
+ assert_nil sheet[2, 1]
157
+ assert_nil sheet.cell(2, 1)
151
158
  row = sheet.row 3
152
159
  assert_equal str4, row[0]
153
- assert_equal str4, sheet[3,0]
154
- assert_equal str4, sheet.cell(3,0)
160
+ assert_equal str4, sheet[3, 0]
161
+ assert_equal str4, sheet.cell(3, 0)
155
162
  assert_nil row[1]
156
- assert_nil sheet[3,1]
157
- assert_nil sheet.cell(3,1)
163
+ assert_nil sheet[3, 1]
164
+ assert_nil sheet.cell(3, 1)
158
165
  row = sheet.row 4
159
166
  assert_equal 0.25, row[0]
160
- assert_equal 0.25, sheet[4,0]
161
- assert_equal 0.25, sheet.cell(4,0)
167
+ assert_equal 0.25, sheet[4, 0]
168
+ assert_equal 0.25, sheet.cell(4, 0)
162
169
  row = sheet.row 5
163
170
  assert_equal 0.75, row[0]
164
- assert_equal 0.75, sheet[5,0]
165
- assert_equal 0.75, sheet.cell(5,0)
171
+ assert_equal 0.75, sheet[5, 0]
172
+ assert_equal 0.75, sheet.cell(5, 0)
166
173
  date = Date.new 1975, 8, 21
167
174
  assert_equal date, row[1]
168
- assert_equal date, sheet[5,1]
169
- assert_equal date, sheet.cell(5,1)
175
+ assert_equal date, sheet[5, 1]
176
+ assert_equal date, sheet.cell(5, 1)
170
177
  row = sheet.row 6
171
178
  assert_equal 1, row[0]
172
- assert_equal 1, sheet[6,0]
173
- assert_equal 1, sheet.cell(6,0)
179
+ assert_equal 1, sheet[6, 0]
180
+ assert_equal 1, sheet.cell(6, 0)
174
181
  row = sheet.row 7
175
182
  assert_nil row[0]
176
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
177
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
178
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
183
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
184
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
185
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
179
186
  row = sheet.row 8
180
187
  assert_equal 0.0001, row[0]
181
188
  row = sheet.row 9
182
189
  assert_equal 0.00009, row[0]
183
190
  assert_equal :green, sheet.row(10).format(11).pattern_fg_color
184
191
  end
192
+
185
193
  def test_version_excel97__ooffice
186
- path = File.join @data, 'test_version_excel97.xls'
194
+ path = File.join @data, "test_version_excel97.xls"
187
195
  book = Spreadsheet.open path
188
196
  assert_instance_of Excel::Workbook, book
189
197
  assert_equal 8, book.biff_version
190
- assert_equal 'Microsoft Excel 97/2000/XP', book.version_string
191
- enc = 'UTF-16LE'
198
+ assert_equal "Microsoft Excel 97/2000/XP", book.version_string
199
+ enc = "UTF-16LE"
192
200
  if defined? Encoding
193
201
  enc = Encoding.find enc
194
202
  end
195
203
  assert_equal enc, book.encoding
196
204
  assert_equal 25, book.formats.size
197
205
  assert_equal 5, book.fonts.size
198
- str1 = 'Shared String'
199
- str2 = 'Another Shared String'
200
- str3 = '1234567890 ' * 1000
201
- str4 = '9876543210 ' * 1000
202
- assert_valid_sst(book, :contains => [str1, str2, str3, str4])
206
+ str1 = "Shared String"
207
+ str2 = "Another Shared String"
208
+ str3 = "1234567890 " * 1000
209
+ str4 = "9876543210 " * 1000
210
+ assert_valid_sst(book, contains: [str1, str2, str3, str4])
203
211
  sheet = book.worksheet 0
204
212
  assert_equal 11, sheet.row_count
205
213
  assert_equal 12, sheet.column_count
206
- useds = [0,0,0,0,0,0,0,1,0,0,11]
207
- unuseds = [2,2,1,1,1,2,1,11,1,2,12]
214
+ useds = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 11]
215
+ unuseds = [2, 2, 1, 1, 1, 2, 1, 11, 1, 2, 12]
208
216
  sheet.each do |row|
209
217
  assert_equal useds.shift, row.first_used
210
218
  assert_equal unuseds.shift, row.first_unused
@@ -212,84 +220,85 @@ module Spreadsheet
212
220
  assert unuseds.empty?, "not all rows were visited in Spreadsheet#each"
213
221
  row = sheet.row 0
214
222
  assert_equal str1, row[0]
215
- assert_equal str1, sheet[0,0]
216
- assert_equal str1, sheet.cell(0,0)
223
+ assert_equal str1, sheet[0, 0]
224
+ assert_equal str1, sheet.cell(0, 0)
217
225
  assert_equal str1, row[1]
218
- assert_equal str1, sheet[0,1]
219
- assert_equal str1, sheet.cell(0,1)
226
+ assert_equal str1, sheet[0, 1]
227
+ assert_equal str1, sheet.cell(0, 1)
220
228
  row = sheet.row 1
221
229
  assert_equal str2, row[0]
222
- assert_equal str2, sheet[1,0]
223
- assert_equal str2, sheet.cell(1,0)
230
+ assert_equal str2, sheet[1, 0]
231
+ assert_equal str2, sheet.cell(1, 0)
224
232
  assert_equal str2, row[1]
225
- assert_equal str2, sheet[1,1]
226
- assert_equal str2, sheet.cell(1,1)
233
+ assert_equal str2, sheet[1, 1]
234
+ assert_equal str2, sheet.cell(1, 1)
227
235
  row = sheet.row 2
228
236
  assert_equal str3, row[0]
229
- assert_equal str3, sheet[2,0]
230
- assert_equal str3, sheet.cell(2,0)
237
+ assert_equal str3, sheet[2, 0]
238
+ assert_equal str3, sheet.cell(2, 0)
231
239
  assert_nil row[1]
232
- assert_nil sheet[2,1]
233
- assert_nil sheet.cell(2,1)
240
+ assert_nil sheet[2, 1]
241
+ assert_nil sheet.cell(2, 1)
234
242
  row = sheet.row 3
235
243
  assert_equal str4, row[0]
236
- assert_equal str4, sheet[3,0]
237
- assert_equal str4, sheet.cell(3,0)
244
+ assert_equal str4, sheet[3, 0]
245
+ assert_equal str4, sheet.cell(3, 0)
238
246
  assert_nil row[1]
239
- assert_nil sheet[3,1]
240
- assert_nil sheet.cell(3,1)
247
+ assert_nil sheet[3, 1]
248
+ assert_nil sheet.cell(3, 1)
241
249
  row = sheet.row 4
242
250
  assert_equal 0.25, row[0]
243
- assert_equal 0.25, sheet[4,0]
244
- assert_equal 0.25, sheet.cell(4,0)
251
+ assert_equal 0.25, sheet[4, 0]
252
+ assert_equal 0.25, sheet.cell(4, 0)
245
253
  row = sheet.row 5
246
254
  assert_equal 0.75, row[0]
247
- assert_equal 0.75, sheet[5,0]
248
- assert_equal 0.75, sheet.cell(5,0)
255
+ assert_equal 0.75, sheet[5, 0]
256
+ assert_equal 0.75, sheet.cell(5, 0)
249
257
  date = Date.new 1975, 8, 21
250
258
  assert_equal date, row[1]
251
- assert_equal date, sheet[5,1]
252
- assert_equal date, sheet.cell(5,1)
259
+ assert_equal date, sheet[5, 1]
260
+ assert_equal date, sheet.cell(5, 1)
253
261
  row = sheet.row 6
254
262
  assert_equal 1, row[0]
255
- assert_equal 1, sheet[6,0]
256
- assert_equal 1, sheet.cell(6,0)
263
+ assert_equal 1, sheet[6, 0]
264
+ assert_equal 1, sheet.cell(6, 0)
257
265
  row = sheet.row 7
258
266
  assert_nil row[0]
259
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
260
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
261
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
267
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
268
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
269
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
262
270
  row = sheet.row 8
263
271
  assert_equal 0.0001, row[0]
264
272
  row = sheet.row 9
265
273
  assert_equal 0.00009, row[0]
266
274
  link = row[1]
267
275
  assert_instance_of Link, link
268
- assert_equal 'Link-Text', link
269
- assert_equal 'http://scm.ywesee.com/spreadsheet', link.url
270
- assert_equal 'http://scm.ywesee.com/spreadsheet', link.href
276
+ assert_equal "Link-Text", link
277
+ assert_equal "http://scm.ywesee.com/spreadsheet", link.url
278
+ assert_equal "http://scm.ywesee.com/spreadsheet", link.href
271
279
  end
280
+
272
281
  def test_version_excel95__ooffice__utf16
273
- Spreadsheet.client_encoding = 'UTF-16LE'
274
- path = File.join @data, 'test_version_excel95.xls'
282
+ Spreadsheet.client_encoding = "UTF-16LE"
283
+ path = File.join @data, "test_version_excel95.xls"
275
284
  book = Spreadsheet.open path
276
285
  assert_instance_of Excel::Workbook, book
277
286
  assert_equal 5, book.biff_version
278
- assert_equal @@iconv.iconv('Microsoft Excel 95'), book.version_string
279
- enc = 'WINDOWS-1252'
287
+ assert_equal @@iconv.iconv("Microsoft Excel 95"), book.version_string
288
+ enc = "WINDOWS-1252"
280
289
  if defined? Encoding
281
290
  enc = Encoding.find enc
282
291
  end
283
292
  assert_equal enc, book.encoding
284
- str1 = @@iconv.iconv('Shared String')
285
- str2 = @@iconv.iconv('Another Shared String')
286
- str3 = @@iconv.iconv(('1234567890 ' * 26)[0,255])
287
- str4 = @@iconv.iconv(('9876543210 ' * 26)[0,255])
293
+ str1 = @@iconv.iconv("Shared String")
294
+ str2 = @@iconv.iconv("Another Shared String")
295
+ str3 = @@iconv.iconv(("1234567890 " * 26)[0, 255])
296
+ str4 = @@iconv.iconv(("9876543210 " * 26)[0, 255])
288
297
  sheet = book.worksheet 0
289
298
  assert_equal 8, sheet.row_count
290
299
  assert_equal 11, sheet.column_count
291
- useds = [0,0,0,0,0,0,0,1]
292
- unuseds = [2,2,1,1,1,1,1,11]
300
+ useds = [0, 0, 0, 0, 0, 0, 0, 1]
301
+ unuseds = [2, 2, 1, 1, 1, 1, 1, 11]
293
302
  sheet.each do |row|
294
303
  assert_equal useds.shift, row.first_used
295
304
  assert_equal unuseds.shift, row.first_unused
@@ -297,72 +306,73 @@ module Spreadsheet
297
306
  assert unuseds.empty?, "not all rows were visited in Spreadsheet#each"
298
307
  row = sheet.row 0
299
308
  assert_equal str1, row[0]
300
- assert_equal str1, sheet[0,0]
301
- assert_equal str1, sheet.cell(0,0)
309
+ assert_equal str1, sheet[0, 0]
310
+ assert_equal str1, sheet.cell(0, 0)
302
311
  assert_equal str1, row[1]
303
- assert_equal str1, sheet[0,1]
304
- assert_equal str1, sheet.cell(0,1)
312
+ assert_equal str1, sheet[0, 1]
313
+ assert_equal str1, sheet.cell(0, 1)
305
314
  row = sheet.row 1
306
315
  assert_equal str2, row[0]
307
- assert_equal str2, sheet[1,0]
308
- assert_equal str2, sheet.cell(1,0)
316
+ assert_equal str2, sheet[1, 0]
317
+ assert_equal str2, sheet.cell(1, 0)
309
318
  assert_equal str2, row[1]
310
- assert_equal str2, sheet[1,1]
311
- assert_equal str2, sheet.cell(1,1)
319
+ assert_equal str2, sheet[1, 1]
320
+ assert_equal str2, sheet.cell(1, 1)
312
321
  row = sheet.row 2
313
322
  assert_equal 510, row[0].send(@@bytesize)
314
323
  assert_equal str3, row[0]
315
- assert_equal str3, sheet[2,0]
316
- assert_equal str3, sheet.cell(2,0)
324
+ assert_equal str3, sheet[2, 0]
325
+ assert_equal str3, sheet.cell(2, 0)
317
326
  assert_nil row[1]
318
- assert_nil sheet[2,1]
319
- assert_nil sheet.cell(2,1)
327
+ assert_nil sheet[2, 1]
328
+ assert_nil sheet.cell(2, 1)
320
329
  row = sheet.row 3
321
330
  assert_equal 510, row[0].send(@@bytesize)
322
331
  assert_equal str4, row[0]
323
- assert_equal str4, sheet[3,0]
324
- assert_equal str4, sheet.cell(3,0)
332
+ assert_equal str4, sheet[3, 0]
333
+ assert_equal str4, sheet.cell(3, 0)
325
334
  assert_nil row[1]
326
- assert_nil sheet[3,1]
327
- assert_nil sheet.cell(3,1)
335
+ assert_nil sheet[3, 1]
336
+ assert_nil sheet.cell(3, 1)
328
337
  row = sheet.row 4
329
338
  assert_equal 0.25, row[0]
330
- assert_equal 0.25, sheet[4,0]
331
- assert_equal 0.25, sheet.cell(4,0)
339
+ assert_equal 0.25, sheet[4, 0]
340
+ assert_equal 0.25, sheet.cell(4, 0)
332
341
  row = sheet.row 5
333
342
  assert_equal 0.75, row[0]
334
- assert_equal 0.75, sheet[5,0]
335
- assert_equal 0.75, sheet.cell(5,0)
343
+ assert_equal 0.75, sheet[5, 0]
344
+ assert_equal 0.75, sheet.cell(5, 0)
336
345
  row = sheet.row 6
337
346
  assert_equal 1, row[0]
338
- assert_equal 1, sheet[6,0]
339
- assert_equal 1, sheet.cell(6,0)
347
+ assert_equal 1, sheet[6, 0]
348
+ assert_equal 1, sheet.cell(6, 0)
340
349
  row = sheet.row 7
341
350
  assert_nil row[0]
342
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
343
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
344
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
351
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
352
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
353
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
345
354
  end
355
+
346
356
  def test_version_excel95__ooffice
347
- path = File.join @data, 'test_version_excel95.xls'
357
+ path = File.join @data, "test_version_excel95.xls"
348
358
  book = Spreadsheet.open path
349
359
  assert_instance_of Excel::Workbook, book
350
360
  assert_equal 5, book.biff_version
351
- assert_equal 'Microsoft Excel 95', book.version_string
352
- enc = 'WINDOWS-1252'
361
+ assert_equal "Microsoft Excel 95", book.version_string
362
+ enc = "WINDOWS-1252"
353
363
  if defined? Encoding
354
364
  enc = Encoding.find enc
355
365
  end
356
366
  assert_equal enc, book.encoding
357
- str1 = 'Shared String'
358
- str2 = 'Another Shared String'
359
- str3 = ('1234567890 ' * 26)[0,255]
360
- str4 = ('9876543210 ' * 26)[0,255]
367
+ str1 = "Shared String"
368
+ str2 = "Another Shared String"
369
+ str3 = ("1234567890 " * 26)[0, 255]
370
+ str4 = ("9876543210 " * 26)[0, 255]
361
371
  sheet = book.worksheet 0
362
372
  assert_equal 8, sheet.row_count
363
373
  assert_equal 11, sheet.column_count
364
- useds = [0,0,0,0,0,0,0,1]
365
- unuseds = [2,2,1,1,1,1,1,11]
374
+ useds = [0, 0, 0, 0, 0, 0, 0, 1]
375
+ unuseds = [2, 2, 1, 1, 1, 1, 1, 11]
366
376
  sheet.each do |row|
367
377
  assert_equal useds.shift, row.first_used
368
378
  assert_equal unuseds.shift, row.first_unused
@@ -370,72 +380,73 @@ module Spreadsheet
370
380
  assert unuseds.empty?, "not all rows were visited in Spreadsheet#each"
371
381
  row = sheet.row 0
372
382
  assert_equal str1, row[0]
373
- assert_equal str1, sheet[0,0]
374
- assert_equal str1, sheet.cell(0,0)
383
+ assert_equal str1, sheet[0, 0]
384
+ assert_equal str1, sheet.cell(0, 0)
375
385
  assert_equal str1, row[1]
376
- assert_equal str1, sheet[0,1]
377
- assert_equal str1, sheet.cell(0,1)
386
+ assert_equal str1, sheet[0, 1]
387
+ assert_equal str1, sheet.cell(0, 1)
378
388
  row = sheet.row 1
379
389
  assert_equal str2, row[0]
380
- assert_equal str2, sheet[1,0]
381
- assert_equal str2, sheet.cell(1,0)
390
+ assert_equal str2, sheet[1, 0]
391
+ assert_equal str2, sheet.cell(1, 0)
382
392
  assert_equal str2, row[1]
383
- assert_equal str2, sheet[1,1]
384
- assert_equal str2, sheet.cell(1,1)
393
+ assert_equal str2, sheet[1, 1]
394
+ assert_equal str2, sheet.cell(1, 1)
385
395
  row = sheet.row 2
386
396
  assert_equal 255, row[0].send(@@bytesize)
387
397
  assert_equal str3, row[0]
388
- assert_equal str3, sheet[2,0]
389
- assert_equal str3, sheet.cell(2,0)
398
+ assert_equal str3, sheet[2, 0]
399
+ assert_equal str3, sheet.cell(2, 0)
390
400
  assert_nil row[1]
391
- assert_nil sheet[2,1]
392
- assert_nil sheet.cell(2,1)
401
+ assert_nil sheet[2, 1]
402
+ assert_nil sheet.cell(2, 1)
393
403
  row = sheet.row 3
394
404
  assert_equal 255, row[0].send(@@bytesize)
395
405
  assert_equal str4, row[0]
396
- assert_equal str4, sheet[3,0]
397
- assert_equal str4, sheet.cell(3,0)
406
+ assert_equal str4, sheet[3, 0]
407
+ assert_equal str4, sheet.cell(3, 0)
398
408
  assert_nil row[1]
399
- assert_nil sheet[3,1]
400
- assert_nil sheet.cell(3,1)
409
+ assert_nil sheet[3, 1]
410
+ assert_nil sheet.cell(3, 1)
401
411
  row = sheet.row 4
402
412
  assert_equal 0.25, row[0]
403
- assert_equal 0.25, sheet[4,0]
404
- assert_equal 0.25, sheet.cell(4,0)
413
+ assert_equal 0.25, sheet[4, 0]
414
+ assert_equal 0.25, sheet.cell(4, 0)
405
415
  row = sheet.row 5
406
416
  assert_equal 0.75, row[0]
407
- assert_equal 0.75, sheet[5,0]
408
- assert_equal 0.75, sheet.cell(5,0)
417
+ assert_equal 0.75, sheet[5, 0]
418
+ assert_equal 0.75, sheet.cell(5, 0)
409
419
  row = sheet.row 6
410
420
  assert_equal 1, row[0]
411
- assert_equal 1, sheet[6,0]
412
- assert_equal 1, sheet.cell(6,0)
421
+ assert_equal 1, sheet[6, 0]
422
+ assert_equal 1, sheet.cell(6, 0)
413
423
  row = sheet.row 7
414
424
  assert_nil row[0]
415
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
416
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
417
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
425
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
426
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
427
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
418
428
  end
429
+
419
430
  def test_version_excel5__ooffice
420
- path = File.join @data, 'test_version_excel5.xls'
431
+ path = File.join @data, "test_version_excel5.xls"
421
432
  book = Spreadsheet.open path
422
433
  assert_instance_of Excel::Workbook, book
423
434
  assert_equal 5, book.biff_version
424
- assert_equal 'Microsoft Excel 95', book.version_string
425
- enc = 'WINDOWS-1252'
435
+ assert_equal "Microsoft Excel 95", book.version_string
436
+ enc = "WINDOWS-1252"
426
437
  if defined? Encoding
427
438
  enc = Encoding.find enc
428
439
  end
429
440
  assert_equal enc, book.encoding
430
- str1 = 'Shared String'
431
- str2 = 'Another Shared String'
432
- str3 = ('1234567890 ' * 26)[0,255]
433
- str4 = ('9876543210 ' * 26)[0,255]
441
+ str1 = "Shared String"
442
+ str2 = "Another Shared String"
443
+ str3 = ("1234567890 " * 26)[0, 255]
444
+ str4 = ("9876543210 " * 26)[0, 255]
434
445
  sheet = book.worksheet 0
435
446
  assert_equal 8, sheet.row_count
436
447
  assert_equal 11, sheet.column_count
437
- useds = [0,0,0,0,0,0,0,1]
438
- unuseds = [2,2,1,1,1,1,1,11]
448
+ useds = [0, 0, 0, 0, 0, 0, 0, 1]
449
+ unuseds = [2, 2, 1, 1, 1, 1, 1, 11]
439
450
  sheet.each do |row|
440
451
  assert_equal useds.shift, row.first_used
441
452
  assert_equal unuseds.shift, row.first_unused
@@ -443,92 +454,95 @@ module Spreadsheet
443
454
  assert unuseds.empty?, "not all rows were visited in Spreadsheet#each"
444
455
  row = sheet.row 0
445
456
  assert_equal str1, row[0]
446
- assert_equal str1, sheet[0,0]
447
- assert_equal str1, sheet.cell(0,0)
457
+ assert_equal str1, sheet[0, 0]
458
+ assert_equal str1, sheet.cell(0, 0)
448
459
  assert_equal str1, row[1]
449
- assert_equal str1, sheet[0,1]
450
- assert_equal str1, sheet.cell(0,1)
460
+ assert_equal str1, sheet[0, 1]
461
+ assert_equal str1, sheet.cell(0, 1)
451
462
  row = sheet.row 1
452
463
  assert_equal str2, row[0]
453
- assert_equal str2, sheet[1,0]
454
- assert_equal str2, sheet.cell(1,0)
464
+ assert_equal str2, sheet[1, 0]
465
+ assert_equal str2, sheet.cell(1, 0)
455
466
  assert_equal str2, row[1]
456
- assert_equal str2, sheet[1,1]
457
- assert_equal str2, sheet.cell(1,1)
467
+ assert_equal str2, sheet[1, 1]
468
+ assert_equal str2, sheet.cell(1, 1)
458
469
  row = sheet.row 2
459
470
  assert_equal 255, row[0].send(@@bytesize)
460
471
  assert_equal str3, row[0]
461
- assert_equal str3, sheet[2,0]
462
- assert_equal str3, sheet.cell(2,0)
472
+ assert_equal str3, sheet[2, 0]
473
+ assert_equal str3, sheet.cell(2, 0)
463
474
  assert_nil row[1]
464
- assert_nil sheet[2,1]
465
- assert_nil sheet.cell(2,1)
475
+ assert_nil sheet[2, 1]
476
+ assert_nil sheet.cell(2, 1)
466
477
  row = sheet.row 3
467
478
  assert_equal 255, row[0].send(@@bytesize)
468
479
  assert_equal str4, row[0]
469
- assert_equal str4, sheet[3,0]
470
- assert_equal str4, sheet.cell(3,0)
480
+ assert_equal str4, sheet[3, 0]
481
+ assert_equal str4, sheet.cell(3, 0)
471
482
  assert_nil row[1]
472
- assert_nil sheet[3,1]
473
- assert_nil sheet.cell(3,1)
483
+ assert_nil sheet[3, 1]
484
+ assert_nil sheet.cell(3, 1)
474
485
  row = sheet.row 4
475
486
  assert_equal 0.25, row[0]
476
- assert_equal 0.25, sheet[4,0]
477
- assert_equal 0.25, sheet.cell(4,0)
487
+ assert_equal 0.25, sheet[4, 0]
488
+ assert_equal 0.25, sheet.cell(4, 0)
478
489
  row = sheet.row 5
479
490
  assert_equal 0.75, row[0]
480
- assert_equal 0.75, sheet[5,0]
481
- assert_equal 0.75, sheet.cell(5,0)
491
+ assert_equal 0.75, sheet[5, 0]
492
+ assert_equal 0.75, sheet.cell(5, 0)
482
493
  row = sheet.row 6
483
494
  assert_equal 1, row[0]
484
- assert_equal 1, sheet[6,0]
485
- assert_equal 1, sheet.cell(6,0)
495
+ assert_equal 1, sheet[6, 0]
496
+ assert_equal 1, sheet.cell(6, 0)
486
497
  row = sheet.row 7
487
498
  assert_nil row[0]
488
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
489
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
490
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
499
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
500
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
501
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
491
502
  end
503
+
492
504
  def test_worksheets
493
- path = File.join @data, 'test_copy.xls'
505
+ path = File.join @data, "test_copy.xls"
494
506
  book = Spreadsheet.open path
495
507
  sheets = book.worksheets
496
508
  assert_equal 3, sheets.size
497
509
  sheet = book.worksheet 0
498
510
  assert_instance_of Excel::Worksheet, sheet
499
- assert_equal sheet, book.worksheet('Sheet1')
511
+ assert_equal sheet, book.worksheet("Sheet1")
500
512
  end
513
+
501
514
  def test_worksheets__utf16
502
- Spreadsheet.client_encoding = 'UTF-16LE'
503
- path = File.join @data, 'test_copy.xls'
515
+ Spreadsheet.client_encoding = "UTF-16LE"
516
+ path = File.join @data, "test_copy.xls"
504
517
  book = Spreadsheet.open path
505
518
  sheets = book.worksheets
506
519
  assert_equal 3, sheets.size
507
520
  sheet = book.worksheet 0
508
521
  assert_instance_of Excel::Worksheet, sheet
509
522
  str = "S\000h\000e\000e\000t\0001\000".dup
510
- if RUBY_VERSION >= '1.9'
511
- str.force_encoding 'UTF-16LE' if str.respond_to?(:force_encoding)
523
+ if RUBY_VERSION >= "1.9"
524
+ str.force_encoding "UTF-16LE" if str.respond_to?(:force_encoding)
512
525
  end
513
526
  assert_equal sheet, book.worksheet(str)
514
527
  end
528
+
515
529
  def test_read_datetime
516
- path = File.join @data, 'test_datetime.xls'
530
+ path = File.join @data, "test_datetime.xls"
517
531
  book = Spreadsheet.open path
518
532
  assert_instance_of Excel::Workbook, book
519
533
  sheet = book.worksheet 0
520
- time = sheet[0,0]
534
+ time = sheet[0, 0]
521
535
  assert_equal 22, time.hour
522
- assert_equal 00, time.min
523
- assert_equal 00, time.sec
524
- time = sheet[1,0]
536
+ assert_equal 0o0, time.min
537
+ assert_equal 0o0, time.sec
538
+ time = sheet[1, 0]
525
539
  assert_equal 1899, time.year
526
540
  assert_equal 12, time.month
527
541
  assert_equal 30, time.day
528
542
  assert_equal 22, time.hour
529
543
  assert_equal 30, time.min
530
544
  assert_equal 45, time.sec
531
- time = sheet[0,1]
545
+ time = sheet[0, 1]
532
546
  assert_equal 1899, time.year
533
547
  assert_equal 12, time.month
534
548
  assert_equal 31, time.day
@@ -536,51 +550,53 @@ module Spreadsheet
536
550
  assert_equal 30, time.min
537
551
  assert_equal 45, time.sec
538
552
  end
553
+
539
554
  def test_change_encoding
540
- path = File.join @data, 'test_version_excel95.xls'
555
+ path = File.join @data, "test_version_excel95.xls"
541
556
  book = Spreadsheet.open path
542
557
  assert_instance_of Excel::Workbook, book
543
558
  assert_equal 5, book.biff_version
544
- assert_equal 'Microsoft Excel 95', book.version_string
545
- enc = 'WINDOWS-1252'
559
+ assert_equal "Microsoft Excel 95", book.version_string
560
+ enc = "WINDOWS-1252"
546
561
  if defined? Encoding
547
562
  enc = Encoding.find enc
548
563
  end
549
564
  assert_equal enc, book.encoding
550
- enc = 'WINDOWS-1256'
565
+ enc = "WINDOWS-1256"
551
566
  if defined? Encoding
552
567
  enc = Encoding.find enc
553
568
  end
554
569
  book.encoding = enc
555
- path = File.join @var, 'test_change_encoding.xls'
570
+ path = File.join @var, "test_change_encoding.xls"
556
571
  book.write path
557
- assert_nothing_raised do book = Spreadsheet.open path end
572
+ assert_nothing_raised { book = Spreadsheet.open path }
558
573
  assert_equal enc, book.encoding
559
574
  end
575
+
560
576
  def test_change_cell
561
- path = File.join @data, 'test_version_excel97.xls'
577
+ path = File.join @data, "test_version_excel97.xls"
562
578
  book = Spreadsheet.open path
563
579
  assert_instance_of Excel::Workbook, book
564
580
  assert_equal 8, book.biff_version
565
- assert_equal 'Microsoft Excel 97/2000/XP', book.version_string
566
- path = File.join @var, 'test_change_cell.xls'
567
- str1 = 'Shared String'
568
- str2 = 'Another Shared String'
569
- str3 = '1234567890 ' * 1000
570
- str4 = '9876543210 ' * 1000
581
+ assert_equal "Microsoft Excel 97/2000/XP", book.version_string
582
+ path = File.join @var, "test_change_cell.xls"
583
+ str1 = "Shared String"
584
+ str2 = "Another Shared String"
585
+ str3 = "1234567890 " * 1000
586
+ str4 = "9876543210 " * 1000
571
587
  str5 = "Link-Text"
572
- assert_valid_sst(book, :is => [str1, str2, str3, str4, str5])
588
+ assert_valid_sst(book, is: [str1, str2, str3, str4, str5])
573
589
  sheet = book.worksheet 0
574
- sheet[0,0] = 4
590
+ sheet[0, 0] = 4
575
591
  row = sheet.row 1
576
592
  row[0] = 3
577
593
  book.write path
578
- assert_nothing_raised do book = Spreadsheet.open path end
594
+ assert_nothing_raised { book = Spreadsheet.open path }
579
595
  sheet = book.worksheet 0
580
596
  assert_equal 11, sheet.row_count
581
597
  assert_equal 12, sheet.column_count
582
- useds = [0,0,0,0,0,0,0,0,0,0,0]
583
- unuseds = [2,2,1,1,1,2,1,11,1,2,12]
598
+ useds = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
599
+ unuseds = [2, 2, 1, 1, 1, 2, 1, 11, 1, 2, 12]
584
600
  sheet.each do |rw|
585
601
  assert_equal useds.shift, rw.first_used
586
602
  assert_equal unuseds.shift, rw.first_unused
@@ -588,85 +604,86 @@ module Spreadsheet
588
604
  assert unuseds.empty?, "not all rows were visited in Spreadsheet#each"
589
605
  row = sheet.row 0
590
606
  assert_equal 4, row[0]
591
- assert_equal 4, sheet[0,0]
592
- assert_equal 4, sheet.cell(0,0)
607
+ assert_equal 4, sheet[0, 0]
608
+ assert_equal 4, sheet.cell(0, 0)
593
609
  assert_equal str1, row[1]
594
- assert_equal str1, sheet[0,1]
595
- assert_equal str1, sheet.cell(0,1)
610
+ assert_equal str1, sheet[0, 1]
611
+ assert_equal str1, sheet.cell(0, 1)
596
612
  row = sheet.row 1
597
613
  assert_equal 3, row[0]
598
- assert_equal 3, sheet[1,0]
599
- assert_equal 3, sheet.cell(1,0)
614
+ assert_equal 3, sheet[1, 0]
615
+ assert_equal 3, sheet.cell(1, 0)
600
616
  assert_equal str2, row[1]
601
- assert_equal str2, sheet[1,1]
602
- assert_equal str2, sheet.cell(1,1)
617
+ assert_equal str2, sheet[1, 1]
618
+ assert_equal str2, sheet.cell(1, 1)
603
619
  row = sheet.row 2
604
620
  assert_equal str3, row[0]
605
- assert_equal str3, sheet[2,0]
606
- assert_equal str3, sheet.cell(2,0)
621
+ assert_equal str3, sheet[2, 0]
622
+ assert_equal str3, sheet.cell(2, 0)
607
623
  assert_nil row[1]
608
- assert_nil sheet[2,1]
609
- assert_nil sheet.cell(2,1)
624
+ assert_nil sheet[2, 1]
625
+ assert_nil sheet.cell(2, 1)
610
626
  row = sheet.row 3
611
627
  assert_equal str4, row[0]
612
- assert_equal str4, sheet[3,0]
613
- assert_equal str4, sheet.cell(3,0)
628
+ assert_equal str4, sheet[3, 0]
629
+ assert_equal str4, sheet.cell(3, 0)
614
630
  assert_nil row[1]
615
- assert_nil sheet[3,1]
616
- assert_nil sheet.cell(3,1)
631
+ assert_nil sheet[3, 1]
632
+ assert_nil sheet.cell(3, 1)
617
633
  row = sheet.row 4
618
634
  assert_equal 0.25, row[0]
619
- assert_equal 0.25, sheet[4,0]
620
- assert_equal 0.25, sheet.cell(4,0)
635
+ assert_equal 0.25, sheet[4, 0]
636
+ assert_equal 0.25, sheet.cell(4, 0)
621
637
  row = sheet.row 5
622
638
  assert_equal 0.75, row[0]
623
- assert_equal 0.75, sheet[5,0]
624
- assert_equal 0.75, sheet.cell(5,0)
639
+ assert_equal 0.75, sheet[5, 0]
640
+ assert_equal 0.75, sheet.cell(5, 0)
625
641
  date = Date.new 1975, 8, 21
626
642
  assert_equal date, row[1]
627
- assert_equal date, sheet[5,1]
628
- assert_equal date, sheet.cell(5,1)
643
+ assert_equal date, sheet[5, 1]
644
+ assert_equal date, sheet.cell(5, 1)
629
645
  row = sheet.row 6
630
646
  assert_equal 1, row[0]
631
- assert_equal 1, sheet[6,0]
632
- assert_equal 1, sheet.cell(6,0)
647
+ assert_equal 1, sheet[6, 0]
648
+ assert_equal 1, sheet.cell(6, 0)
633
649
  row = sheet.row 7
634
650
  assert_nil row[0]
635
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
636
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
637
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
651
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
652
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
653
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
638
654
  row = sheet.row 8
639
655
  assert_equal 0.0001, row[0]
640
656
  row = sheet.row 9
641
657
  assert_equal 0.00009, row[0]
642
658
  end
659
+
643
660
  def test_change_cell__complete_sst_rewrite
644
- path = File.join @data, 'test_version_excel97.xls'
661
+ path = File.join @data, "test_version_excel97.xls"
645
662
  book = Spreadsheet.open path
646
663
  assert_instance_of Excel::Workbook, book
647
664
  assert_equal 8, book.biff_version
648
- assert_equal 'Microsoft Excel 97/2000/XP', book.version_string
649
- path = File.join @var, 'test_change_cell.xls'
650
- str1 = 'Shared String'
651
- str2 = 'Another Shared String'
652
- str3 = '1234567890 ' * 1000
653
- str4 = '9876543210 ' * 1000
654
- str5 = 'Link-Text'
655
- assert_valid_sst(book, :is => [str1, str2, str3, str4, str5])
665
+ assert_equal "Microsoft Excel 97/2000/XP", book.version_string
666
+ path = File.join @var, "test_change_cell.xls"
667
+ str1 = "Shared String"
668
+ str2 = "Another Shared String"
669
+ str3 = "1234567890 " * 1000
670
+ str4 = "9876543210 " * 1000
671
+ str5 = "Link-Text"
672
+ assert_valid_sst(book, is: [str1, str2, str3, str4, str5])
656
673
  sheet = book.worksheet 0
657
- sheet[0,0] = 4
658
- str6 = 'A completely different String'
659
- sheet[0,1] = str6
674
+ sheet[0, 0] = 4
675
+ str6 = "A completely different String"
676
+ sheet[0, 1] = str6
660
677
  row = sheet.row 1
661
678
  row[0] = 3
662
679
  book.write path
663
- assert_nothing_raised do book = Spreadsheet.open path end
664
- assert_valid_sst(book, :is => [str2, str3, str4, str5, str6])
680
+ assert_nothing_raised { book = Spreadsheet.open path }
681
+ assert_valid_sst(book, is: [str2, str3, str4, str5, str6])
665
682
  sheet = book.worksheet 0
666
683
  assert_equal 11, sheet.row_count
667
684
  assert_equal 12, sheet.column_count
668
- useds = [0,0,0,0,0,0,0,0,0,0,0]
669
- unuseds = [2,2,1,1,1,2,1,11,1,2,12]
685
+ useds = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
686
+ unuseds = [2, 2, 1, 1, 1, 2, 1, 11, 1, 2, 12]
670
687
  sheet.each do |rw|
671
688
  assert_equal useds.shift, rw.first_used
672
689
  assert_equal unuseds.shift, rw.first_unused
@@ -674,63 +691,64 @@ module Spreadsheet
674
691
  assert unuseds.empty?, "not all rows were visited in Spreadsheet#each"
675
692
  row = sheet.row 0
676
693
  assert_equal 4, row[0]
677
- assert_equal 4, sheet[0,0]
678
- assert_equal 4, sheet.cell(0,0)
694
+ assert_equal 4, sheet[0, 0]
695
+ assert_equal 4, sheet.cell(0, 0)
679
696
  assert_equal str6, row[1]
680
- assert_equal str6, sheet[0,1]
681
- assert_equal str6, sheet.cell(0,1)
697
+ assert_equal str6, sheet[0, 1]
698
+ assert_equal str6, sheet.cell(0, 1)
682
699
  row = sheet.row 1
683
700
  assert_equal 3, row[0]
684
- assert_equal 3, sheet[1,0]
685
- assert_equal 3, sheet.cell(1,0)
701
+ assert_equal 3, sheet[1, 0]
702
+ assert_equal 3, sheet.cell(1, 0)
686
703
  assert_equal str2, row[1]
687
- assert_equal str2, sheet[1,1]
688
- assert_equal str2, sheet.cell(1,1)
704
+ assert_equal str2, sheet[1, 1]
705
+ assert_equal str2, sheet.cell(1, 1)
689
706
  row = sheet.row 2
690
707
  assert_equal str3, row[0]
691
- assert_equal str3, sheet[2,0]
692
- assert_equal str3, sheet.cell(2,0)
708
+ assert_equal str3, sheet[2, 0]
709
+ assert_equal str3, sheet.cell(2, 0)
693
710
  assert_nil row[1]
694
- assert_nil sheet[2,1]
695
- assert_nil sheet.cell(2,1)
711
+ assert_nil sheet[2, 1]
712
+ assert_nil sheet.cell(2, 1)
696
713
  row = sheet.row 3
697
714
  assert_equal str4, row[0]
698
- assert_equal str4, sheet[3,0]
699
- assert_equal str4, sheet.cell(3,0)
715
+ assert_equal str4, sheet[3, 0]
716
+ assert_equal str4, sheet.cell(3, 0)
700
717
  assert_nil row[1]
701
- assert_nil sheet[3,1]
702
- assert_nil sheet.cell(3,1)
718
+ assert_nil sheet[3, 1]
719
+ assert_nil sheet.cell(3, 1)
703
720
  row = sheet.row 4
704
721
  assert_equal 0.25, row[0]
705
- assert_equal 0.25, sheet[4,0]
706
- assert_equal 0.25, sheet.cell(4,0)
722
+ assert_equal 0.25, sheet[4, 0]
723
+ assert_equal 0.25, sheet.cell(4, 0)
707
724
  row = sheet.row 5
708
725
  assert_equal 0.75, row[0]
709
- assert_equal 0.75, sheet[5,0]
710
- assert_equal 0.75, sheet.cell(5,0)
726
+ assert_equal 0.75, sheet[5, 0]
727
+ assert_equal 0.75, sheet.cell(5, 0)
711
728
  date = Date.new 1975, 8, 21
712
729
  assert_equal date, row[1]
713
- assert_equal date, sheet[5,1]
714
- assert_equal date, sheet.cell(5,1)
730
+ assert_equal date, sheet[5, 1]
731
+ assert_equal date, sheet.cell(5, 1)
715
732
  row = sheet.row 6
716
733
  assert_equal 1, row[0]
717
- assert_equal 1, sheet[6,0]
718
- assert_equal 1, sheet.cell(6,0)
734
+ assert_equal 1, sheet[6, 0]
735
+ assert_equal 1, sheet.cell(6, 0)
719
736
  row = sheet.row 7
720
737
  assert_nil row[0]
721
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
722
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
723
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
738
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
739
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
740
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
724
741
  row = sheet.row 8
725
742
  assert_equal 0.0001, row[0]
726
743
  row = sheet.row 9
727
744
  assert_equal 0.00009, row[0]
728
745
  end
746
+
729
747
  def test_write_to_stringio
730
748
  book = Spreadsheet::Excel::Workbook.new
731
- sheet = book.create_worksheet :name => 'My Worksheet'
732
- sheet[0,0] = 'my cell'
733
- data = StringIO.new ''.dup
749
+ sheet = book.create_worksheet name: "My Worksheet"
750
+ sheet[0, 0] = "my cell"
751
+ data = StringIO.new "".dup
734
752
  assert_nothing_raised do
735
753
  book.write data
736
754
  end
@@ -740,100 +758,101 @@ module Spreadsheet
740
758
  assert_instance_of Spreadsheet::Excel::Workbook, book
741
759
  assert_equal 1, book.worksheets.size
742
760
  sheet = book.worksheet 0
743
- assert_equal 'My Worksheet', sheet.name
744
- assert_equal 'my cell', sheet[0,0]
761
+ assert_equal "My Worksheet", sheet.name
762
+ assert_equal "my cell", sheet[0, 0]
745
763
  end
764
+
746
765
  def test_write_new_workbook
747
766
  book = Spreadsheet::Workbook.new
748
- path = File.join @var, 'test_write_workbook.xls'
767
+ path = File.join @var, "test_write_workbook.xls"
749
768
  sheet1 = book.create_worksheet
750
- str1 = 'My Shared String'
751
- str2 = 'Another Shared String'
769
+ str1 = "My Shared String"
770
+ str2 = "Another Shared String"
752
771
  assert_equal 1, (str1.size + str2.size) % 2,
753
772
  "str3 should start at an odd offset to test splitting of wide strings"
754
- str3 = '–––––––––– ' * 1000
755
- str4 = '1234567890 ' * 1000
756
- fmt1 = Format.new :italic => true, :color => :blue
757
- sheet1.format_column 1, fmt1, :width => 20
758
- fmt2 = Format.new(:weight => :bold, :color => :yellow)
773
+ str3 = "–––––––––– " * 1000
774
+ str4 = "1234567890 " * 1000
775
+ fmt1 = Format.new italic: true, color: :blue
776
+ sheet1.format_column 1, fmt1, width: 20
777
+ fmt2 = Format.new(weight: :bold, color: :yellow)
759
778
  sheet1.format_column 2, fmt2
760
- sheet1.format_column 3, Format.new(:weight => :bold, :color => :red)
779
+ sheet1.format_column 3, Format.new(weight: :bold, color: :red)
761
780
  sheet1.format_column 6..9, fmt1
762
- sheet1.format_column [4,5,7], fmt2
781
+ sheet1.format_column [4, 5, 7], fmt2
763
782
  sheet1.row(0).height = 20
764
- sheet1[0,0] = str1
783
+ sheet1[0, 0] = str1
765
784
  sheet1.row(0).push str1
766
785
  sheet1.row(1).concat [str2, str2]
767
- sheet1[2,0] = str3
768
- sheet1[3,0] = str4
769
- fmt = Format.new :color => 'red'
770
- sheet1[4,0] = 0.25
786
+ sheet1[2, 0] = str3
787
+ sheet1[3, 0] = str4
788
+ fmt = Format.new color: "red"
789
+ sheet1[4, 0] = 0.25
771
790
  sheet1.row(4).set_format 0, fmt
772
- fmt = Format.new :color => 'aqua'
773
- sheet1[5,0] = 0.75
791
+ fmt = Format.new color: "aqua"
792
+ sheet1[5, 0] = 0.75
774
793
  sheet1.row(5).set_format 0, fmt
775
- link = Link.new 'http://scm.ywesee.com/?p=spreadsheet;a=summary',
776
- 'The Spreadsheet GitWeb', 'top'
777
- sheet1[5,1] = link
778
- sheet1[6,0] = 1
779
- fmt = Format.new :color => 'green'
794
+ link = Link.new "http://scm.ywesee.com/?p=spreadsheet;a=summary",
795
+ "The Spreadsheet GitWeb", "top"
796
+ sheet1[5, 1] = link
797
+ sheet1[6, 0] = 1
798
+ fmt = Format.new color: "green"
780
799
  sheet1.row(6).set_format 0, fmt
781
- sheet1[6,1] = Date.new 2008, 10, 10
782
- sheet1[6,2] = Date.new 2008, 10, 12
783
- fmt = Format.new :number_format => 'D.M.YY'
800
+ sheet1[6, 1] = Date.new 2008, 10, 10
801
+ sheet1[6, 2] = Date.new 2008, 10, 12
802
+ fmt = Format.new number_format: "D.M.YY"
784
803
  sheet1.row(6).set_format 1, fmt
785
804
  sheet1.update_row 7, nil, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
786
- sheet1[8,0] = 0.0005
787
- sheet1[8,1] = 0.005
788
- sheet1[8,2] = 0.05
789
- sheet1[8,3] = 10.5
790
- sheet1[8,4] = 1.05
791
- sheet1[8,5] = 100.5
792
- sheet1[8,6] = 10.05
793
- sheet1[8,7] = 1.005
794
- sheet1[9,0] = 100.5
795
- sheet1[9,1] = 10.05
796
- sheet1[9,2] = 1.005
797
- sheet1[9,3] = 1000.5
798
- sheet1[9,4] = 100.05
799
- sheet1[9,5] = 10.005
800
- sheet1[9,6] = 1.0005
801
- sheet1[10,0] = 10000.5
802
- sheet1[10,1] = 1000.05
803
- sheet1[10,2] = 100.005
804
- sheet1[10,3] = 10.0005
805
- sheet1[10,4] = 1.00005
806
- sheet1.insert_row 9, ['a', 'b', 'c']
807
- assert_equal 'a', sheet1[9,0]
808
- assert_equal 'b', sheet1[9,1]
809
- assert_equal 'c', sheet1[9,2]
805
+ sheet1[8, 0] = 0.0005
806
+ sheet1[8, 1] = 0.005
807
+ sheet1[8, 2] = 0.05
808
+ sheet1[8, 3] = 10.5
809
+ sheet1[8, 4] = 1.05
810
+ sheet1[8, 5] = 100.5
811
+ sheet1[8, 6] = 10.05
812
+ sheet1[8, 7] = 1.005
813
+ sheet1[9, 0] = 100.5
814
+ sheet1[9, 1] = 10.05
815
+ sheet1[9, 2] = 1.005
816
+ sheet1[9, 3] = 1000.5
817
+ sheet1[9, 4] = 100.05
818
+ sheet1[9, 5] = 10.005
819
+ sheet1[9, 6] = 1.0005
820
+ sheet1[10, 0] = 10000.5
821
+ sheet1[10, 1] = 1000.05
822
+ sheet1[10, 2] = 100.005
823
+ sheet1[10, 3] = 10.0005
824
+ sheet1[10, 4] = 1.00005
825
+ sheet1.insert_row 9, ["a", "b", "c"]
826
+ assert_equal "a", sheet1[9, 0]
827
+ assert_equal "b", sheet1[9, 1]
828
+ assert_equal "c", sheet1[9, 2]
810
829
  sheet1.delete_row 9
811
830
  row = sheet1.row(11)
812
831
  row.height = 40
813
- row.push 'x'
832
+ row.push "x"
814
833
  row.pop
815
- book.create_worksheet :name => 'my name' #=> sheet2
834
+ book.create_worksheet name: "my name" #=> sheet2
816
835
  book.write path
817
- Spreadsheet.client_encoding = 'UTF-16LE'
836
+ Spreadsheet.client_encoding = "UTF-16LE"
818
837
  str1 = @@iconv.iconv str1
819
838
  str2 = @@iconv.iconv str2
820
839
  str3 = @@iconv.iconv str3
821
840
  str4 = @@iconv.iconv str4
822
- assert_nothing_raised do book = Spreadsheet.open path end
823
- if RUBY_VERSION >= '1.9'
824
- assert_equal 'UTF-16LE', book.encoding.name
841
+ assert_nothing_raised { book = Spreadsheet.open path }
842
+ if RUBY_VERSION >= "1.9"
843
+ assert_equal "UTF-16LE", book.encoding.name
825
844
  else
826
- assert_equal 'UTF-16LE', book.encoding
845
+ assert_equal "UTF-16LE", book.encoding
827
846
  end
828
- assert_valid_sst(book, :contains => [str1, str2, str3, str4])
847
+ assert_valid_sst(book, contains: [str1, str2, str3, str4])
829
848
  assert_equal 2, book.worksheets.size
830
849
  sheet = book.worksheets.first
831
850
  assert_instance_of Spreadsheet::Excel::Worksheet, sheet
832
851
  name = "W\000o\000r\000k\000s\000h\000e\000e\000t\0001\000".dup
833
- name.force_encoding 'UTF-16LE' if name.respond_to?(:force_encoding)
852
+ name.force_encoding "UTF-16LE" if name.respond_to?(:force_encoding)
834
853
  assert_equal name, sheet.name
835
854
  assert_not_nil sheet.offset
836
- assert_not_nil col = sheet.column(1)
855
+ assert_not_nil(col = sheet.column(1))
837
856
  assert_equal true, col.default_format.font.italic?
838
857
  assert_equal :blue, col.default_format.font.color
839
858
  assert_equal 20, col.width
@@ -841,142 +860,143 @@ module Spreadsheet
841
860
  assert_equal col.default_format, row.format(1)
842
861
  assert_equal 20, row.height
843
862
  assert_equal str1, row[0]
844
- assert_equal str1, sheet[0,0]
845
- assert_equal str1, sheet.cell(0,0)
863
+ assert_equal str1, sheet[0, 0]
864
+ assert_equal str1, sheet.cell(0, 0)
846
865
  assert_equal str1, row[1]
847
- assert_equal str1, sheet[0,1]
848
- assert_equal str1, sheet.cell(0,1)
866
+ assert_equal str1, sheet[0, 1]
867
+ assert_equal str1, sheet.cell(0, 1)
849
868
  row = sheet.row 1
850
869
  assert_equal str2, row[0]
851
- assert_equal str2, sheet[1,0]
852
- assert_equal str2, sheet.cell(1,0)
870
+ assert_equal str2, sheet[1, 0]
871
+ assert_equal str2, sheet.cell(1, 0)
853
872
  assert_equal str2, row[1]
854
- assert_equal str2, sheet[1,1]
855
- assert_equal str2, sheet.cell(1,1)
873
+ assert_equal str2, sheet[1, 1]
874
+ assert_equal str2, sheet.cell(1, 1)
856
875
  row = sheet.row 2
857
876
  assert_equal str3, row[0]
858
- assert_equal str3, sheet[2,0]
859
- assert_equal str3, sheet.cell(2,0)
877
+ assert_equal str3, sheet[2, 0]
878
+ assert_equal str3, sheet.cell(2, 0)
860
879
  assert_nil row[1]
861
- assert_nil sheet[2,1]
862
- assert_nil sheet.cell(2,1)
880
+ assert_nil sheet[2, 1]
881
+ assert_nil sheet.cell(2, 1)
863
882
  row = sheet.row 3
864
883
  assert_equal str4, row[0]
865
- assert_equal str4, sheet[3,0]
866
- assert_equal str4, sheet.cell(3,0)
884
+ assert_equal str4, sheet[3, 0]
885
+ assert_equal str4, sheet.cell(3, 0)
867
886
  assert_nil row[1]
868
- assert_nil sheet[3,1]
869
- assert_nil sheet.cell(3,1)
887
+ assert_nil sheet[3, 1]
888
+ assert_nil sheet.cell(3, 1)
870
889
  row = sheet.row 4
871
890
  assert_equal :red, row.format(0).font.color
872
891
  assert_equal 0.25, row[0]
873
- assert_equal 0.25, sheet[4,0]
874
- assert_equal 0.25, sheet.cell(4,0)
892
+ assert_equal 0.25, sheet[4, 0]
893
+ assert_equal 0.25, sheet.cell(4, 0)
875
894
  row = sheet.row 5
876
895
  assert_equal :cyan, row.format(0).font.color
877
896
  assert_equal 0.75, row[0]
878
- assert_equal 0.75, sheet[5,0]
879
- assert_equal 0.75, sheet.cell(5,0)
897
+ assert_equal 0.75, sheet[5, 0]
898
+ assert_equal 0.75, sheet.cell(5, 0)
880
899
  link = row[1]
881
900
  assert_instance_of Link, link
882
- url = @@iconv.iconv 'http://scm.ywesee.com/?p=spreadsheet;a=summary'
883
- assert_equal @@iconv.iconv('The Spreadsheet GitWeb'), link
901
+ url = @@iconv.iconv "http://scm.ywesee.com/?p=spreadsheet;a=summary"
902
+ assert_equal @@iconv.iconv("The Spreadsheet GitWeb"), link
884
903
  assert_equal url, link.url
885
- assert_equal @@iconv.iconv('top'), link.fragment
904
+ assert_equal @@iconv.iconv("top"), link.fragment
886
905
  row = sheet.row 6
887
906
  assert_equal :green, row.format(0).font.color
888
907
  assert_equal 1, row[0]
889
- assert_equal 1, sheet[6,0]
890
- assert_equal 1, sheet.cell(6,0)
891
- assert_equal @@iconv.iconv('D.M.YY'), row.format(1).number_format
908
+ assert_equal 1, sheet[6, 0]
909
+ assert_equal 1, sheet.cell(6, 0)
910
+ assert_equal @@iconv.iconv("D.M.YY"), row.format(1).number_format
892
911
  date = Date.new 2008, 10, 10
893
912
  assert_equal date, row[1]
894
- assert_equal date, sheet[6,1]
895
- assert_equal date, sheet.cell(6,1)
896
- assert_equal @@iconv.iconv('DD.MM.YYYY'), row.format(2).number_format
913
+ assert_equal date, sheet[6, 1]
914
+ assert_equal date, sheet.cell(6, 1)
915
+ assert_equal @@iconv.iconv("DD.MM.YYYY"), row.format(2).number_format
897
916
  date = Date.new 2008, 10, 12
898
917
  assert_equal date, row[2]
899
- assert_equal date, sheet[6,2]
900
- assert_equal date, sheet.cell(6,2)
918
+ assert_equal date, sheet[6, 2]
919
+ assert_equal date, sheet.cell(6, 2)
901
920
  row = sheet.row 7
902
921
  assert_nil row[0]
903
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
904
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
905
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
906
- assert_equal 0.0005, sheet1[8,0]
907
- assert_equal 0.005, sheet1[8,1]
908
- assert_equal 0.05, sheet1[8,2]
909
- assert_equal 10.5, sheet1[8,3]
910
- assert_equal 1.05, sheet1[8,4]
911
- assert_equal 100.5, sheet1[8,5]
912
- assert_equal 10.05, sheet1[8,6]
913
- assert_equal 1.005, sheet1[8,7]
914
- assert_equal 100.5, sheet1[9,0]
915
- assert_equal 10.05, sheet1[9,1]
916
- assert_equal 1.005, sheet1[9,2]
917
- assert_equal 1000.5, sheet1[9,3]
918
- assert_equal 100.05, sheet1[9,4]
919
- assert_equal 10.005, sheet1[9,5]
920
- assert_equal 1.0005, sheet1[9,6]
921
- assert_equal 10000.5, sheet1[10,0]
922
- assert_equal 1000.05, sheet1[10,1]
923
- assert_equal 100.005, sheet1[10,2]
924
- assert_equal 10.0005, sheet1[10,3]
925
- assert_equal 1.00005, sheet1[10,4]
922
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
923
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
924
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
925
+ assert_equal 0.0005, sheet1[8, 0]
926
+ assert_equal 0.005, sheet1[8, 1]
927
+ assert_equal 0.05, sheet1[8, 2]
928
+ assert_equal 10.5, sheet1[8, 3]
929
+ assert_equal 1.05, sheet1[8, 4]
930
+ assert_equal 100.5, sheet1[8, 5]
931
+ assert_equal 10.05, sheet1[8, 6]
932
+ assert_equal 1.005, sheet1[8, 7]
933
+ assert_equal 100.5, sheet1[9, 0]
934
+ assert_equal 10.05, sheet1[9, 1]
935
+ assert_equal 1.005, sheet1[9, 2]
936
+ assert_equal 1000.5, sheet1[9, 3]
937
+ assert_equal 100.05, sheet1[9, 4]
938
+ assert_equal 10.005, sheet1[9, 5]
939
+ assert_equal 1.0005, sheet1[9, 6]
940
+ assert_equal 10000.5, sheet1[10, 0]
941
+ assert_equal 1000.05, sheet1[10, 1]
942
+ assert_equal 100.005, sheet1[10, 2]
943
+ assert_equal 10.0005, sheet1[10, 3]
944
+ assert_equal 1.00005, sheet1[10, 4]
926
945
  assert_equal 40, sheet1.row(11).height
927
946
  assert_instance_of Spreadsheet::Excel::Worksheet, sheet
928
947
  sheet = book.worksheets.last
929
948
  name = "m\000y\000 \000n\000a\000m\000e\000".dup
930
- name.force_encoding 'UTF-16LE' if name.respond_to?(:force_encoding)
949
+ name.force_encoding "UTF-16LE" if name.respond_to?(:force_encoding)
931
950
  assert_equal name, sheet.name
932
951
  assert_not_nil sheet.offset
933
952
  end
953
+
934
954
  def test_write_new_workbook__utf16
935
- Spreadsheet.client_encoding = 'UTF-16LE'
955
+ Spreadsheet.client_encoding = "UTF-16LE"
936
956
  book = Spreadsheet::Workbook.new
937
- path = File.join @var, 'test_write_workbook.xls'
957
+ path = File.join @var, "test_write_workbook.xls"
938
958
  sheet1 = book.create_worksheet
939
- str1 = @@iconv.iconv 'Shared String'
940
- str2 = @@iconv.iconv 'Another Shared String'
941
- str3 = @@iconv.iconv('1234567890 ' * 1000)
942
- str4 = @@iconv.iconv('9876543210 ' * 1000)
943
- fmt = Format.new :italic => true, :color => :blue
944
- sheet1.format_column 1, fmt, :width => 20
945
- sheet1[0,0] = str1
959
+ str1 = @@iconv.iconv "Shared String"
960
+ str2 = @@iconv.iconv "Another Shared String"
961
+ str3 = @@iconv.iconv("1234567890 " * 1000)
962
+ str4 = @@iconv.iconv("9876543210 " * 1000)
963
+ fmt = Format.new italic: true, color: :blue
964
+ sheet1.format_column 1, fmt, width: 20
965
+ sheet1[0, 0] = str1
946
966
  sheet1.row(0).push str1
947
967
  sheet1.row(1).concat [str2, str2]
948
- sheet1[2,0] = str3
949
- sheet1[3,0] = str4
950
- fmt = Format.new :color => 'red'
951
- sheet1[4,0] = 0.25
968
+ sheet1[2, 0] = str3
969
+ sheet1[3, 0] = str4
970
+ fmt = Format.new color: "red"
971
+ sheet1[4, 0] = 0.25
952
972
  sheet1.row(4).set_format 0, fmt
953
- fmt = Format.new :color => 'aqua'
954
- sheet1[5,0] = 0.75
973
+ fmt = Format.new color: "aqua"
974
+ sheet1[5, 0] = 0.75
955
975
  sheet1.row(5).set_format 0, fmt
956
- sheet1[6,0] = 1
957
- fmt = Format.new :color => 'green'
976
+ sheet1[6, 0] = 1
977
+ fmt = Format.new color: "green"
958
978
  sheet1.row(6).set_format 0, fmt
959
- sheet1[6,1] = Date.new 2008, 10, 10
960
- sheet1[6,2] = Date.new 2008, 10, 12
961
- fmt = Format.new :number_format => @@iconv.iconv("DD.MM.YYYY")
979
+ sheet1[6, 1] = Date.new 2008, 10, 10
980
+ sheet1[6, 2] = Date.new 2008, 10, 12
981
+ fmt = Format.new number_format: @@iconv.iconv("DD.MM.YYYY")
962
982
  sheet1.row(6).set_format 1, fmt
963
983
  sheet1.update_row 7, nil, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0
964
984
  sheet1.row(8).default_format = fmt
965
- sheet1[8,0] = @@iconv.iconv 'formatted when empty'
966
- book.create_worksheet :name => @@iconv.iconv("my name") #=> sheet2
985
+ sheet1[8, 0] = @@iconv.iconv "formatted when empty"
986
+ book.create_worksheet name: @@iconv.iconv("my name") #=> sheet2
967
987
  book.write path
968
- Spreadsheet.client_encoding = 'UTF-8'
969
- str1 = 'Shared String'
970
- str2 = 'Another Shared String'
971
- str3 = '1234567890 ' * 1000
972
- str4 = '9876543210 ' * 1000
973
- assert_nothing_raised do book = Spreadsheet.open path end
974
- if RUBY_VERSION >= '1.9'
975
- assert_equal 'UTF-16LE', book.encoding.name
988
+ Spreadsheet.client_encoding = "UTF-8"
989
+ str1 = "Shared String"
990
+ str2 = "Another Shared String"
991
+ str3 = "1234567890 " * 1000
992
+ str4 = "9876543210 " * 1000
993
+ assert_nothing_raised { book = Spreadsheet.open path }
994
+ if RUBY_VERSION >= "1.9"
995
+ assert_equal "UTF-16LE", book.encoding.name
976
996
  else
977
- assert_equal 'UTF-16LE', book.encoding
997
+ assert_equal "UTF-16LE", book.encoding
978
998
  end
979
- assert_valid_sst(book, :is => [str1, str2, str3, str4, "formatted when empty"])
999
+ assert_valid_sst(book, is: [str1, str2, str3, str4, "formatted when empty"])
980
1000
  assert_equal 2, book.worksheets.size
981
1001
  sheet = book.worksheets.first
982
1002
  assert_instance_of Spreadsheet::Excel::Worksheet, sheet
@@ -988,137 +1008,141 @@ module Spreadsheet
988
1008
  row = sheet.row 0
989
1009
  assert_equal col.default_format, row.format(1)
990
1010
  assert_equal str1, row[0]
991
- assert_equal str1, sheet[0,0]
992
- assert_equal str1, sheet.cell(0,0)
1011
+ assert_equal str1, sheet[0, 0]
1012
+ assert_equal str1, sheet.cell(0, 0)
993
1013
  assert_equal str1, row[1]
994
- assert_equal str1, sheet[0,1]
995
- assert_equal str1, sheet.cell(0,1)
1014
+ assert_equal str1, sheet[0, 1]
1015
+ assert_equal str1, sheet.cell(0, 1)
996
1016
  row = sheet.row 1
997
1017
  assert_equal str2, row[0]
998
- assert_equal str2, sheet[1,0]
999
- assert_equal str2, sheet.cell(1,0)
1018
+ assert_equal str2, sheet[1, 0]
1019
+ assert_equal str2, sheet.cell(1, 0)
1000
1020
  assert_equal str2, row[1]
1001
- assert_equal str2, sheet[1,1]
1002
- assert_equal str2, sheet.cell(1,1)
1021
+ assert_equal str2, sheet[1, 1]
1022
+ assert_equal str2, sheet.cell(1, 1)
1003
1023
  row = sheet.row 2
1004
1024
  assert_equal str3, row[0]
1005
- assert_equal str3, sheet[2,0]
1006
- assert_equal str3, sheet.cell(2,0)
1025
+ assert_equal str3, sheet[2, 0]
1026
+ assert_equal str3, sheet.cell(2, 0)
1007
1027
  assert_nil row[1]
1008
- assert_nil sheet[2,1]
1009
- assert_nil sheet.cell(2,1)
1028
+ assert_nil sheet[2, 1]
1029
+ assert_nil sheet.cell(2, 1)
1010
1030
  row = sheet.row 3
1011
1031
  assert_equal str4, row[0]
1012
- assert_equal str4, sheet[3,0]
1013
- assert_equal str4, sheet.cell(3,0)
1032
+ assert_equal str4, sheet[3, 0]
1033
+ assert_equal str4, sheet.cell(3, 0)
1014
1034
  assert_nil row[1]
1015
- assert_nil sheet[3,1]
1016
- assert_nil sheet.cell(3,1)
1035
+ assert_nil sheet[3, 1]
1036
+ assert_nil sheet.cell(3, 1)
1017
1037
  row = sheet.row 4
1018
1038
  assert_equal :red, row.format(0).font.color
1019
1039
  assert_equal 0.25, row[0]
1020
- assert_equal 0.25, sheet[4,0]
1021
- assert_equal 0.25, sheet.cell(4,0)
1040
+ assert_equal 0.25, sheet[4, 0]
1041
+ assert_equal 0.25, sheet.cell(4, 0)
1022
1042
  row = sheet.row 5
1023
1043
  assert_equal :cyan, row.format(0).font.color
1024
1044
  assert_equal 0.75, row[0]
1025
- assert_equal 0.75, sheet[5,0]
1026
- assert_equal 0.75, sheet.cell(5,0)
1045
+ assert_equal 0.75, sheet[5, 0]
1046
+ assert_equal 0.75, sheet.cell(5, 0)
1027
1047
  row = sheet.row 6
1028
1048
  assert_equal :green, row.format(0).font.color
1029
1049
  assert_equal 1, row[0]
1030
- assert_equal 1, sheet[6,0]
1031
- assert_equal 1, sheet.cell(6,0)
1032
- assert_equal 'DD.MM.YYYY', row.format(1).number_format
1050
+ assert_equal 1, sheet[6, 0]
1051
+ assert_equal 1, sheet.cell(6, 0)
1052
+ assert_equal "DD.MM.YYYY", row.format(1).number_format
1033
1053
  date = Date.new 2008, 10, 10
1034
1054
  assert_equal date, row[1]
1035
- assert_equal date, sheet[6,1]
1036
- assert_equal date, sheet.cell(6,1)
1037
- assert_equal 'DD.MM.YYYY', row.format(2).number_format
1055
+ assert_equal date, sheet[6, 1]
1056
+ assert_equal date, sheet.cell(6, 1)
1057
+ assert_equal "DD.MM.YYYY", row.format(2).number_format
1038
1058
  date = Date.new 2008, 10, 12
1039
1059
  assert_equal date, row[2]
1040
- assert_equal date, sheet[6,2]
1041
- assert_equal date, sheet.cell(6,2)
1060
+ assert_equal date, sheet[6, 2]
1061
+ assert_equal date, sheet.cell(6, 2)
1042
1062
  row = sheet.row 7
1043
1063
  assert_nil row[0]
1044
- assert_equal [1,2,3,4,5,6,7,8,9,0], row[1,10]
1045
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet[7,1..10]
1046
- assert_equal [1,2,3,4,5,6,7,8,9,0], sheet.cell(7,1..10)
1064
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], row[1, 10]
1065
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet[7, 1..10]
1066
+ assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9, 0], sheet.cell(7, 1..10)
1047
1067
  row = sheet.row 8
1048
- assert_equal 'formatted when empty', row[0]
1068
+ assert_equal "formatted when empty", row[0]
1049
1069
  assert_not_nil row.default_format
1050
1070
  assert_instance_of Spreadsheet::Excel::Worksheet, sheet
1051
1071
  sheet = book.worksheets.last
1052
1072
  assert_equal "my name",
1053
- sheet.name
1073
+ sheet.name
1054
1074
  assert_not_nil sheet.offset
1055
1075
  end
1076
+
1056
1077
  def test_template
1057
- template = File.join @data, 'test_copy.xls'
1058
- output = File.join @var, 'test_template.xls'
1078
+ template = File.join @data, "test_copy.xls"
1079
+ output = File.join @var, "test_template.xls"
1059
1080
  book = Spreadsheet.open template
1060
1081
  sheet1 = book.worksheet 0
1061
- sheet1.row(4).replace [ 'Daniel J. Berger', 'U.S.A.',
1062
- 'Author of original code for Spreadsheet::Excel' ]
1082
+ sheet1.row(4).replace ["Daniel J. Berger", "U.S.A.",
1083
+ "Author of original code for Spreadsheet::Excel"]
1063
1084
  book.write output
1064
1085
  assert_nothing_raised do
1065
1086
  book = Spreadsheet.open output
1066
1087
  end
1067
1088
  sheet = book.worksheet 0
1068
1089
  row = sheet.row(4)
1069
- assert_equal 'Daniel J. Berger', row[0]
1090
+ assert_equal "Daniel J. Berger", row[0]
1070
1091
  end
1092
+
1071
1093
  def test_bignum
1072
1094
  smallnum = 0x1fffffff
1073
1095
  bignum = smallnum + 1
1074
1096
  book = Spreadsheet::Workbook.new
1075
1097
  sheet = book.create_worksheet
1076
- sheet[0,0] = bignum
1077
- sheet[1,0] = -bignum
1078
- sheet[0,1] = smallnum
1079
- sheet[1,1] = -smallnum
1080
- sheet[0,2] = bignum - 0.1
1081
- sheet[1,2] = -bignum - 0.1
1082
- sheet[0,3] = smallnum - 0.1
1083
- sheet[1,3] = -smallnum - 0.1
1084
- path = File.join @var, 'test_big-number.xls'
1098
+ sheet[0, 0] = bignum
1099
+ sheet[1, 0] = -bignum
1100
+ sheet[0, 1] = smallnum
1101
+ sheet[1, 1] = -smallnum
1102
+ sheet[0, 2] = bignum - 0.1
1103
+ sheet[1, 2] = -bignum - 0.1
1104
+ sheet[0, 3] = smallnum - 0.1
1105
+ sheet[1, 3] = -smallnum - 0.1
1106
+ path = File.join @var, "test_big-number.xls"
1085
1107
  book.write path
1086
1108
  assert_nothing_raised do
1087
1109
  book = Spreadsheet.open path
1088
1110
  end
1089
- assert_equal bignum, book.worksheet(0)[0,0]
1090
- assert_equal(-bignum, book.worksheet(0)[1,0])
1091
- assert_equal smallnum, book.worksheet(0)[0,1]
1092
- assert_equal(-smallnum, book.worksheet(0)[1,1])
1093
- assert_equal bignum - 0.1, book.worksheet(0)[0,2]
1094
- assert_equal(-bignum - 0.1, book.worksheet(0)[1,2])
1095
- assert_equal smallnum - 0.1, book.worksheet(0)[0,3]
1096
- assert_equal(-smallnum - 0.1, book.worksheet(0)[1,3])
1111
+ assert_equal bignum, book.worksheet(0)[0, 0]
1112
+ assert_equal(-bignum, book.worksheet(0)[1, 0])
1113
+ assert_equal smallnum, book.worksheet(0)[0, 1]
1114
+ assert_equal(-smallnum, book.worksheet(0)[1, 1])
1115
+ assert_equal bignum - 0.1, book.worksheet(0)[0, 2]
1116
+ assert_equal(-bignum - 0.1, book.worksheet(0)[1, 2])
1117
+ assert_equal smallnum - 0.1, book.worksheet(0)[0, 3]
1118
+ assert_equal(-smallnum - 0.1, book.worksheet(0)[1, 3])
1097
1119
  end
1120
+
1098
1121
  def test_bigfloat
1099
1122
  # reported in http://rubyforge.org/tracker/index.php?func=detail&aid=24119&group_id=678&atid=2677
1100
1123
  bigfloat = 10000000.0
1101
1124
  book = Spreadsheet::Workbook.new
1102
1125
  sheet = book.create_worksheet
1103
- sheet[0,0] = bigfloat
1104
- sheet[0,1] = bigfloat + 0.1
1105
- sheet[0,2] = bigfloat - 0.1
1106
- sheet[1,0] = -bigfloat
1107
- sheet[1,1] = -bigfloat + 0.1
1108
- sheet[1,2] = -bigfloat - 0.1
1109
- path = File.join @var, 'test_big-float.xls'
1126
+ sheet[0, 0] = bigfloat
1127
+ sheet[0, 1] = bigfloat + 0.1
1128
+ sheet[0, 2] = bigfloat - 0.1
1129
+ sheet[1, 0] = -bigfloat
1130
+ sheet[1, 1] = -bigfloat + 0.1
1131
+ sheet[1, 2] = -bigfloat - 0.1
1132
+ path = File.join @var, "test_big-float.xls"
1110
1133
  book.write path
1111
1134
  assert_nothing_raised do
1112
1135
  book = Spreadsheet.open path
1113
1136
  end
1114
1137
  sheet = book.worksheet(0)
1115
- assert_equal bigfloat, sheet[0,0]
1116
- assert_equal bigfloat + 0.1, sheet[0,1]
1117
- assert_equal bigfloat - 0.1, sheet[0,2]
1118
- assert_equal(-bigfloat, sheet[1,0])
1119
- assert_equal(-bigfloat + 0.1, sheet[1,1])
1120
- assert_equal(-bigfloat - 0.1, sheet[1,2])
1138
+ assert_equal bigfloat, sheet[0, 0]
1139
+ assert_equal bigfloat + 0.1, sheet[0, 1]
1140
+ assert_equal bigfloat - 0.1, sheet[0, 2]
1141
+ assert_equal(-bigfloat, sheet[1, 0])
1142
+ assert_equal(-bigfloat + 0.1, sheet[1, 1])
1143
+ assert_equal(-bigfloat - 0.1, sheet[1, 2])
1121
1144
  end
1145
+
1122
1146
  def test_datetime__off_by_one
1123
1147
  # reported in http://rubyforge.org/tracker/index.php?func=detail&aid=24414&group_id=678&atid=2677
1124
1148
  datetime1 = DateTime.new(2008)
@@ -1127,20 +1151,20 @@ module Spreadsheet
1127
1151
  date2 = Date.new(2009)
1128
1152
  book = Spreadsheet::Workbook.new
1129
1153
  sheet = book.create_worksheet
1130
- sheet[0,0] = datetime1
1131
- sheet[0,1] = datetime2
1132
- sheet[1,0] = date1
1133
- sheet[1,1] = date2
1134
- path = File.join @var, 'test_datetime.xls'
1154
+ sheet[0, 0] = datetime1
1155
+ sheet[0, 1] = datetime2
1156
+ sheet[1, 0] = date1
1157
+ sheet[1, 1] = date2
1158
+ path = File.join @var, "test_datetime.xls"
1135
1159
  book.write path
1136
1160
  assert_nothing_raised do
1137
1161
  book = Spreadsheet.open path
1138
1162
  end
1139
1163
  sheet = book.worksheet(0)
1140
- assert_equal datetime1, sheet[0,0]
1141
- assert_equal datetime2, sheet[0,1]
1142
- assert_equal date1, sheet[1,0]
1143
- assert_equal date2, sheet[1,1]
1164
+ assert_equal datetime1, sheet[0, 0]
1165
+ assert_equal datetime2, sheet[0, 1]
1166
+ assert_equal date1, sheet[1, 0]
1167
+ assert_equal date2, sheet[1, 1]
1144
1168
  assert_equal date1, sheet.row(0).date(0)
1145
1169
  assert_equal datetime1, sheet.row(1).datetime(0)
1146
1170
  end
@@ -1158,7 +1182,7 @@ module Spreadsheet
1158
1182
  sheet.insert_row 0, [r1, r2, r3]
1159
1183
  sheet.insert_row 1, [r4, r5, r6]
1160
1184
 
1161
- path = File.join @var, 'test_rational.xls'
1185
+ path = File.join @var, "test_rational.xls"
1162
1186
  book.write path
1163
1187
 
1164
1188
  assert_nothing_raised do
@@ -1175,38 +1199,42 @@ module Spreadsheet
1175
1199
  end
1176
1200
 
1177
1201
  def test_sharedfmla
1178
- path = File.join @data, 'test_formula.xls'
1202
+ path = File.join @data, "test_formula.xls"
1179
1203
  book = Spreadsheet.open path
1180
1204
  assert_instance_of Excel::Workbook, book
1181
1205
  sheet = book.worksheet 0
1182
1206
  64.times do |idx|
1183
- assert_equal '5026', sheet[idx.next, 2].value
1207
+ assert_equal "5026", sheet[idx.next, 2].value
1184
1208
  end
1185
1209
  end
1210
+
1186
1211
  def test_missing_row_op
1187
- path = File.join @data, 'test_missing_row.xls'
1212
+ path = File.join @data, "test_missing_row.xls"
1188
1213
  book = Spreadsheet.open path
1189
1214
  assert_instance_of Excel::Workbook, book
1190
1215
  sheet = book.worksheet 0
1191
- assert_not_nil sheet[1,0]
1192
- assert_not_nil sheet[2,1]
1216
+ assert_not_nil sheet[1, 0]
1217
+ assert_not_nil sheet[2, 1]
1193
1218
  end
1219
+
1194
1220
  def test_changes
1195
- path = File.join @data, 'test_changes.xls'
1221
+ path = File.join @data, "test_changes.xls"
1196
1222
  book = Spreadsheet.open path
1197
1223
  assert_instance_of Excel::Workbook, book
1198
1224
  sheet = book.worksheet 1
1199
- sheet[20,0] = 'Ciao Mundo!'
1200
- target = File.join @var, 'test_changes.xls'
1201
- assert_nothing_raised do book.write target end
1225
+ sheet[20, 0] = "Ciao Mundo!"
1226
+ target = File.join @var, "test_changes.xls"
1227
+ assert_nothing_raised { book.write target }
1202
1228
  end
1229
+
1203
1230
  def test_long_sst_record
1204
- path = File.join @data, 'test_long_sst_record.xls'
1231
+ path = File.join @data, "test_long_sst_record.xls"
1205
1232
  book = Spreadsheet.open path
1206
1233
  sheet = book.worksheet(0)
1207
- expected_result = 'A1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998'
1208
- assert_equal(expected_result, sheet[0,0])
1234
+ expected_result = "A1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998"
1235
+ assert_equal(expected_result, sheet[0, 0])
1209
1236
  end
1237
+
1210
1238
  def test_special_chars
1211
1239
  book = Spreadsheet::Workbook.new
1212
1240
  sheet = book.create_worksheet
@@ -1222,14 +1250,14 @@ module Spreadsheet
1222
1250
  sheet = book.worksheet(0)
1223
1251
  sheet.ensure_rows_read # FIXME HACK
1224
1252
  assert sheet.protected?, "Expected sheet to be protected"
1225
- assert_equal Spreadsheet::Excel::Password.password_hash('testing'), sheet.password_hash
1253
+ assert_equal Spreadsheet::Excel::Password.password_hash("testing"), sheet.password_hash
1226
1254
  end
1227
1255
 
1228
1256
  def test_write_protected_sheet
1229
- path = File.join @var, 'test_protected.xls'
1257
+ path = File.join @var, "test_protected.xls"
1230
1258
  book = Spreadsheet::Workbook.new
1231
1259
  sheet = book.create_worksheet
1232
- sheet.protect! 'secret'
1260
+ sheet.protect! "secret"
1233
1261
  assert_nothing_raised do
1234
1262
  book.write path
1235
1263
  end
@@ -1238,43 +1266,43 @@ module Spreadsheet
1238
1266
  sheet = read_back.worksheet(0)
1239
1267
  sheet.ensure_rows_read # FIXME HACK
1240
1268
  assert sheet.protected?, "Expected sheet to be proteced"
1241
- assert_equal Spreadsheet::Excel::Password.password_hash('secret'), sheet.password_hash
1269
+ assert_equal Spreadsheet::Excel::Password.password_hash("secret"), sheet.password_hash
1242
1270
  end
1243
1271
 
1244
- =begin
1245
- def test_read_baltic
1246
- path = File.join @data, 'test_baltic.xls'
1247
- assert_nothing_raised do
1248
- Spreadsheet.open path
1249
- end
1250
- end
1251
- =end
1272
+ # def test_read_baltic
1273
+ # path = File.join @data, 'test_baltic.xls'
1274
+ # assert_nothing_raised do
1275
+ # Spreadsheet.open path
1276
+ # end
1277
+ # end
1252
1278
  def test_write_frozen_string
1253
- Spreadsheet.client_encoding = 'UTF-16LE'
1279
+ Spreadsheet.client_encoding = "UTF-16LE"
1254
1280
  book = Spreadsheet::Workbook.new
1255
- path = File.join @var, 'test_write_workbook.xls'
1281
+ path = File.join @var, "test_write_workbook.xls"
1256
1282
  sheet1 = book.create_worksheet
1257
1283
  str1 = "Frozen String.".freeze
1258
- sheet1[0,0] = str1
1284
+ sheet1[0, 0] = str1
1259
1285
  sheet1.row(0).push str1
1260
1286
  assert_nothing_raised do
1261
1287
  book.write path
1262
1288
  end
1263
1289
  end
1290
+
1264
1291
  def test_read_merged_cells
1265
- path = File.join(@data, 'test_merged_cells.xls')
1292
+ path = File.join(@data, "test_merged_cells.xls")
1266
1293
  book = Spreadsheet.open(path)
1267
1294
  assert_equal 8, book.biff_version
1268
1295
  sheet = book.worksheet(0)
1269
- sheet[0,0] # trigger read_worksheet
1296
+ sheet[0, 0] # trigger read_worksheet
1270
1297
  assert_equal [[2, 4, 1, 1], [3, 3, 2, 3]], sheet.merged_cells
1271
1298
  end
1299
+
1272
1300
  def test_read_borders
1273
- path = File.join @data, 'test_borders.xls'
1301
+ path = File.join @data, "test_borders.xls"
1274
1302
  book = Spreadsheet.open path
1275
1303
  assert_instance_of Excel::Workbook, book
1276
1304
  sheet = book.worksheet 0
1277
- format = sheet.row(0).format 0
1305
+ format = sheet.row(0).format 0
1278
1306
  assert_equal :none, format.left
1279
1307
  assert_equal :thin, format.top
1280
1308
  assert_equal :medium, format.right
@@ -1284,9 +1312,10 @@ module Spreadsheet
1284
1312
  assert_equal :green, format.right_color
1285
1313
  assert_equal :yellow, format.bottom_color
1286
1314
  end
1315
+
1287
1316
  def test_write_borders
1288
1317
  book = Spreadsheet::Workbook.new
1289
- path = File.join @var, 'test_write_borders.xls'
1318
+ path = File.join @var, "test_write_borders.xls"
1290
1319
  sheet1 = book.create_worksheet
1291
1320
  (sheet1.row(0).format 0).border = :hair
1292
1321
  (sheet1.row(0).format 0).border_color = :brown
@@ -1302,12 +1331,12 @@ module Spreadsheet
1302
1331
  end
1303
1332
 
1304
1333
  def test_adding_data_to_existing_file
1305
- path = File.join @data, 'test_adding_data_to_existing_file.xls'
1334
+ path = File.join @data, "test_adding_data_to_existing_file.xls"
1306
1335
  book = Spreadsheet.open path
1307
1336
  assert_equal(1, book.worksheet(0).rows.count)
1308
1337
 
1309
1338
  book.worksheet(0).insert_row(1, [12, 23, 34, 45])
1310
- temp_file = Tempfile.new('temp')
1339
+ temp_file = Tempfile.new("temp")
1311
1340
  book.write(temp_file.path)
1312
1341
 
1313
1342
  temp_book = Spreadsheet.open temp_file.path
@@ -1317,22 +1346,23 @@ module Spreadsheet
1317
1346
  end
1318
1347
 
1319
1348
  def test_comment
1320
- path = File.join @data, 'test_comment.xls'
1349
+ path = File.join @data, "test_comment.xls"
1321
1350
  book = Spreadsheet.open path
1322
1351
  assert_instance_of Excel::Workbook, book
1323
1352
  sheet = book.worksheet 0
1324
1353
  sheet.ensure_rows_read
1325
- #Now two commented fields in sheet
1326
- assert_equal(true, book.worksheet(0).notes.has_key?([0,18]))
1327
- assert_equal(true, book.worksheet(0).notes.has_key?([0,2]))
1328
- assert_equal(false, book.worksheet(0).notes.has_key?([0,3]))
1354
+ # Now two commented fields in sheet
1355
+ assert_equal(true, book.worksheet(0).notes.has_key?([0, 18]))
1356
+ assert_equal(true, book.worksheet(0).notes.has_key?([0, 2]))
1357
+ assert_equal(false, book.worksheet(0).notes.has_key?([0, 3]))
1329
1358
  assert_equal("Another Author:\n0: switch it off\n1: switch it on",
1330
- book.worksheet(0).notes[[0,18]])
1359
+ book.worksheet(0).notes[[0, 18]])
1331
1360
  assert_equal("Some author:\nI have a register name",
1332
- book.worksheet(0).notes[[0,2]])
1361
+ book.worksheet(0).notes[[0, 2]])
1333
1362
  end
1363
+
1334
1364
  def test_read_pagesetup
1335
- path = File.join @data, 'test_pagesetup.xls'
1365
+ path = File.join @data, "test_pagesetup.xls"
1336
1366
  book = Spreadsheet.open path
1337
1367
  assert_instance_of Excel::Workbook, book
1338
1368
  sheet = book.worksheet(0)
@@ -1342,7 +1372,7 @@ module Spreadsheet
1342
1372
 
1343
1373
  def test_write_pagesetup
1344
1374
  book = Spreadsheet::Workbook.new
1345
- path = File.join @var, 'test_write_pagesetup.xls'
1375
+ path = File.join @var, "test_write_pagesetup.xls"
1346
1376
  sheet1 = book.create_worksheet
1347
1377
  sheet1.pagesetup[:orientation] = :landscape
1348
1378
  sheet1.pagesetup[:adjust_to] = 93
@@ -1357,7 +1387,7 @@ module Spreadsheet
1357
1387
  end
1358
1388
 
1359
1389
  def test_read_margins
1360
- path = File.join @data, 'test_margin.xls'
1390
+ path = File.join @data, "test_margin.xls"
1361
1391
  book = Spreadsheet.open path
1362
1392
  assert_instance_of Excel::Workbook, book
1363
1393
  sheet = book.worksheet(0)
@@ -1366,7 +1396,7 @@ module Spreadsheet
1366
1396
 
1367
1397
  def test_write_margins
1368
1398
  book = Spreadsheet::Workbook.new
1369
- path = File.join @var, 'test_write_margins.xls'
1399
+ path = File.join @var, "test_write_margins.xls"
1370
1400
  sheet1 = book.create_worksheet
1371
1401
  sheet1.margins[:left] = 3
1372
1402
  assert_nothing_raised do
@@ -1379,7 +1409,7 @@ module Spreadsheet
1379
1409
  end
1380
1410
 
1381
1411
  def test_read_worksheet_visibility
1382
- path = File.join @data, 'test_worksheet_visibility.xls'
1412
+ path = File.join @data, "test_worksheet_visibility.xls"
1383
1413
  book = Spreadsheet.open path
1384
1414
  assert_instance_of Excel::Workbook, book
1385
1415
  assert_equal(:visible, book.worksheet(0).visibility)
@@ -1388,7 +1418,7 @@ module Spreadsheet
1388
1418
 
1389
1419
  def test_write_worksheet_visibility
1390
1420
  book = Spreadsheet::Workbook.new
1391
- path = File.join @var, 'test_write_worksheet_visibility.xls'
1421
+ path = File.join @var, "test_write_worksheet_visibility.xls"
1392
1422
  sheet1 = book.create_worksheet
1393
1423
  sheet1.visibility = :hidden
1394
1424
  _sheet2 = book.create_worksheet
@@ -1402,31 +1432,31 @@ module Spreadsheet
1402
1432
  end
1403
1433
 
1404
1434
  def test_append_and_reopen
1405
- filename = path = File.join @var, 'test.xls'
1406
- sheet_name = 'Test Sheet'
1435
+ filename = File.join @var, "test.xls"
1436
+ sheet_name = "Test Sheet"
1407
1437
 
1408
1438
  # Create excel
1409
1439
  excel = Spreadsheet::Workbook.new(filename)
1410
1440
  sheet = excel.create_worksheet(name: sheet_name)
1411
- sheet.row(1).replace ['Data']
1441
+ sheet.row(1).replace ["Data"]
1412
1442
  excel.write(filename)
1413
1443
 
1414
1444
  # Append something
1415
- excel = Spreadsheet.open(filename, 'a+')
1445
+ excel = Spreadsheet.open(filename, "a+")
1416
1446
  sheet = excel.worksheet(sheet_name)
1417
- sheet.row(2).replace ['Data2']
1447
+ sheet.row(2).replace ["Data2"]
1418
1448
  filename = "test2.xls"
1419
1449
  excel.write(filename)
1420
1450
 
1421
1451
  # Reopen
1422
1452
  excel = Spreadsheet.open filename
1423
- sheet = excel.worksheet sheet_name
1453
+ excel.worksheet sheet_name
1424
1454
  ensure
1425
1455
  File.delete filename if File.exist? filename
1426
1456
  end
1427
1457
 
1428
1458
  def test_text_drawing
1429
- path = File.join @data, 'test_text_drawing.xls'
1459
+ path = File.join @data, "test_text_drawing.xls"
1430
1460
  book = Spreadsheet.open path
1431
1461
  assert_nothing_raised do
1432
1462
  book.worksheet(0).row(0)
@@ -1434,17 +1464,17 @@ module Spreadsheet
1434
1464
  end
1435
1465
 
1436
1466
  def test_compact
1437
- path = File.join @data, 'test_compact_many_rows.xls'
1467
+ path = File.join @data, "test_compact_many_rows.xls"
1438
1468
  book = Spreadsheet.open path
1439
1469
  sheets = book.worksheets
1440
1470
  assert_equal 1, sheets.size
1441
1471
  sheet = book.worksheet 0
1442
1472
  assert_instance_of Excel::Worksheet, sheet
1443
- assert_equal sheet, book.worksheet('Planilha1')
1473
+ assert_equal sheet, book.worksheet("Planilha1")
1444
1474
  assert_equal sheet.dimensions, [0, 65534, 0, 25]
1445
1475
  sheet.compact!
1446
1476
  assert_equal sheet.dimensions, [0, 502, 0, 1]
1447
- path = File.join @data, 'test_sizes.xls'
1477
+ path = File.join @data, "test_sizes.xls"
1448
1478
  book = Spreadsheet.open path
1449
1479
  sheet = book.worksheet 0
1450
1480
  assert_instance_of Excel::Worksheet, sheet
@@ -1461,7 +1491,7 @@ module Spreadsheet
1461
1491
  assert_equal sheet.dimensions, [0, 4, 0, 4]
1462
1492
  sheet.compact!
1463
1493
  assert_equal sheet.dimensions, [0, 2, 0, 2]
1464
- path = File.join @data, 'test_compact_format_date.xls'
1494
+ path = File.join @data, "test_compact_format_date.xls"
1465
1495
  book = Spreadsheet.open path
1466
1496
  sheet = book.worksheet 0
1467
1497
  assert_instance_of Excel::Worksheet, sheet
@@ -1498,6 +1528,5 @@ module Spreadsheet
1498
1528
  assert_equal opts[:length], sorted_strings
1499
1529
  end
1500
1530
  end
1501
-
1502
1531
  end
1503
1532
  end