rubyXL-git-ref-6002046 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +20 -0
  3. data/Gemfile.lock +63 -0
  4. data/LICENSE.txt +20 -0
  5. data/README.rdoc +197 -0
  6. data/Rakefile +58 -0
  7. data/VERSION +1 -0
  8. data/lib/rubyXL.rb +21 -0
  9. data/lib/rubyXL/cell.rb +325 -0
  10. data/lib/rubyXL/generic_storage.rb +40 -0
  11. data/lib/rubyXL/objects/border.rb +53 -0
  12. data/lib/rubyXL/objects/cell_style.rb +73 -0
  13. data/lib/rubyXL/objects/color.rb +23 -0
  14. data/lib/rubyXL/objects/column_range.rb +88 -0
  15. data/lib/rubyXL/objects/data_validation.rb +31 -0
  16. data/lib/rubyXL/objects/defined_name.rb +27 -0
  17. data/lib/rubyXL/objects/fill.rb +42 -0
  18. data/lib/rubyXL/objects/font.rb +109 -0
  19. data/lib/rubyXL/objects/formula.rb +8 -0
  20. data/lib/rubyXL/objects/ooxml_object.rb +177 -0
  21. data/lib/rubyXL/objects/reference.rb +98 -0
  22. data/lib/rubyXL/objects/sheet_view.rb +62 -0
  23. data/lib/rubyXL/objects/worksheet.rb +11 -0
  24. data/lib/rubyXL/parser.rb +307 -0
  25. data/lib/rubyXL/private_class.rb +95 -0
  26. data/lib/rubyXL/shared_strings.rb +35 -0
  27. data/lib/rubyXL/workbook.rb +342 -0
  28. data/lib/rubyXL/worksheet.rb +1118 -0
  29. data/lib/rubyXL/writer/app_writer.rb +51 -0
  30. data/lib/rubyXL/writer/calc_chain_writer.rb +18 -0
  31. data/lib/rubyXL/writer/content_types_writer.rb +113 -0
  32. data/lib/rubyXL/writer/core_writer.rb +34 -0
  33. data/lib/rubyXL/writer/generic_writer.rb +33 -0
  34. data/lib/rubyXL/writer/root_rels_writer.rb +17 -0
  35. data/lib/rubyXL/writer/shared_strings_writer.rb +21 -0
  36. data/lib/rubyXL/writer/styles_writer.rb +64 -0
  37. data/lib/rubyXL/writer/theme_writer.rb +337 -0
  38. data/lib/rubyXL/writer/workbook_rels_writer.rb +43 -0
  39. data/lib/rubyXL/writer/workbook_writer.rb +73 -0
  40. data/lib/rubyXL/writer/worksheet_writer.rb +164 -0
  41. data/lib/rubyXL/zip.rb +20 -0
  42. data/rdoc/created.rid +36 -0
  43. data/rdoc/fonts.css +167 -0
  44. data/rdoc/fonts/Lato-Light.ttf +0 -0
  45. data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
  46. data/rdoc/fonts/Lato-Regular.ttf +0 -0
  47. data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
  48. data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
  49. data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
  50. data/rdoc/images/add.png +0 -0
  51. data/rdoc/images/arrow_up.png +0 -0
  52. data/rdoc/images/brick.png +0 -0
  53. data/rdoc/images/brick_link.png +0 -0
  54. data/rdoc/images/bug.png +0 -0
  55. data/rdoc/images/bullet_black.png +0 -0
  56. data/rdoc/images/bullet_toggle_minus.png +0 -0
  57. data/rdoc/images/bullet_toggle_plus.png +0 -0
  58. data/rdoc/images/date.png +0 -0
  59. data/rdoc/images/delete.png +0 -0
  60. data/rdoc/images/find.png +0 -0
  61. data/rdoc/images/loadingAnimation.gif +0 -0
  62. data/rdoc/images/macFFBgHack.png +0 -0
  63. data/rdoc/images/package.png +0 -0
  64. data/rdoc/images/page_green.png +0 -0
  65. data/rdoc/images/page_white_text.png +0 -0
  66. data/rdoc/images/page_white_width.png +0 -0
  67. data/rdoc/images/plugin.png +0 -0
  68. data/rdoc/images/ruby.png +0 -0
  69. data/rdoc/images/tag_blue.png +0 -0
  70. data/rdoc/images/tag_green.png +0 -0
  71. data/rdoc/images/transparent.png +0 -0
  72. data/rdoc/images/wrench.png +0 -0
  73. data/rdoc/images/wrench_orange.png +0 -0
  74. data/rdoc/images/zoom.png +0 -0
  75. data/rdoc/js/darkfish.js +140 -0
  76. data/rdoc/js/jquery.js +18 -0
  77. data/rdoc/js/navigation.js +142 -0
  78. data/rdoc/js/search.js +109 -0
  79. data/rdoc/js/search_index.js +1 -0
  80. data/rdoc/js/searcher.js +228 -0
  81. data/rdoc/rdoc.css +580 -0
  82. data/rubyXL-git-ref-6002046.gemspec +143 -0
  83. data/spec/lib/cell_spec.rb +407 -0
  84. data/spec/lib/color_spec.rb +14 -0
  85. data/spec/lib/parser_spec.rb +80 -0
  86. data/spec/lib/workbook_spec.rb +73 -0
  87. data/spec/lib/worksheet_spec.rb +1789 -0
  88. metadata +231 -0
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rubyXL'
3
+
4
+ describe RubyXL::Color do
5
+ describe '.validate_color' do
6
+ it 'should return true if a valid hex color without a # is passed' do
7
+ RubyXL::Color.validate_color('0fbCAd').should == true
8
+ end
9
+
10
+ it 'should cause an error if an invalid hex color code or one with a # is passed' do
11
+ lambda {RubyXL::Color.validate_color('#G')}.should raise_error
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,80 @@
1
+ require 'rubygems'
2
+ require 'rubyXL'
3
+
4
+ describe RubyXL::Parser do
5
+
6
+ before do
7
+ @workbook = RubyXL::Workbook.new
8
+ @workbook.add_worksheet("Test Worksheet")
9
+
10
+ ws = @workbook.add_worksheet("Escape Test")
11
+ ws.add_cell(0,0, "&")
12
+ ws.add_cell(0,1, "<")
13
+ ws.add_cell(0,2, ">")
14
+
15
+ ws.add_cell(1,0, "&")#TODO#.datatype = RubyXL::Cell::SHARED_STRING
16
+ ws.add_cell(1,1, "<")#TODO#.datatype = RubyXL::Cell::SHARED_STRING
17
+ ws.add_cell(1,2, ">")#TODO#.datatype = RubyXL::Cell::SHARED_STRING
18
+
19
+ @time_str = Time.now.to_s
20
+ @file = @time_str + '.xlsx'
21
+ @workbook.write(@file)
22
+ end
23
+
24
+ describe '.parse' do
25
+ it 'should parse a valid Excel xlsx or xlsm workbook correctly' do
26
+ @workbook2 = RubyXL::Parser.parse(@file)
27
+
28
+ @workbook2.worksheets.size.should == @workbook.worksheets.size
29
+ @workbook2[0].sheet_data.should == @workbook[0].sheet_data
30
+ @workbook2[0].sheet_name.should == @workbook[0].sheet_name
31
+ end
32
+
33
+ it 'should cause an error if an xlsx or xlsm workbook is not passed' do
34
+ lambda {@workbook2 = RubyXL::Parser.parse(@time_str+".xls")}.should raise_error
35
+ end
36
+
37
+ it 'should not cause an error if an xlsx or xlsm workbook is not passed but the skip_filename_check option is used' do
38
+ filename = @time_str
39
+ FileUtils.cp(@file, filename)
40
+
41
+ lambda {@workbook2 = RubyXL::Parser.parse(filename)}.should raise_error
42
+ lambda {@workbook2 = RubyXL::Parser.parse(filename, :skip_filename_check => true)}.should_not raise_error
43
+
44
+ File.delete(filename)
45
+ end
46
+
47
+ it 'should only read the data and not any of the styles (for the sake of speed) when passed true' do
48
+ @workbook2 = RubyXL::Parser.parse(@file, :data_only => true)
49
+
50
+ @workbook2.worksheets.size.should == @workbook.worksheets.size
51
+ @workbook2[0].sheet_data.should == @workbook[0].sheet_data
52
+ @workbook2[0].sheet_name.should == @workbook[0].sheet_name
53
+ end
54
+
55
+ it 'should construct consistent number formats' do
56
+ @workbook2 = RubyXL::Parser.parse(@file)
57
+ @workbook2.num_fmts.should be_an(Array)
58
+ # Need to directly read XML to check the size...
59
+ # @workbook2.num_fmts.size.should == @workbook2.num_fmts[:attributes][:count]
60
+ end
61
+
62
+ it 'should unescape HTML entities properly' do
63
+ @workbook2 = RubyXL::Parser.parse(@file)
64
+ @workbook2["Escape Test"][0][0].value.should == "&"
65
+ @workbook2["Escape Test"][0][1].value.should == "<"
66
+ @workbook2["Escape Test"][0][2].value.should == ">"
67
+
68
+ @workbook2["Escape Test"][1][0].value.should == "&"
69
+ @workbook2["Escape Test"][1][1].value.should == "<"
70
+ @workbook2["Escape Test"][1][2].value.should == ">"
71
+ end
72
+
73
+ end
74
+
75
+ after do
76
+ if File.exist?(@file)
77
+ File.delete(@file)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'rubyXL'
3
+
4
+ describe RubyXL::Workbook do
5
+ before do
6
+ @workbook = RubyXL::Workbook.new
7
+ @worksheet = @workbook.add_worksheet('Test Worksheet')
8
+
9
+ (0..10).each do |i|
10
+ (0..10).each do |j|
11
+ @worksheet.add_cell(i, j, "#{i}:#{j}")
12
+ end
13
+ end
14
+
15
+ @cell = @worksheet[0][0]
16
+ end
17
+
18
+ describe '.new' do
19
+ it 'should automatically create a blank worksheet named "Sheet1"' do
20
+ @workbook[0].sheet_name.should == 'Sheet1'
21
+ end
22
+ end
23
+
24
+ describe '[]' do
25
+ it 'should properly locate worksheet by index' do
26
+ @workbook[1].sheet_name.should == 'Test Worksheet'
27
+ end
28
+
29
+ it 'should properly locate worksheet by name' do
30
+ @workbook['Test Worksheet'].sheet_name.should == 'Test Worksheet'
31
+ end
32
+ end
33
+
34
+ describe '.add_worksheet' do
35
+ it 'when not given a name, it should automatically pick a name "SheetX" that is not taken yet' do
36
+ @workbook.add_worksheet
37
+ @workbook['Sheet2'].sheet_name.should == 'Sheet2'
38
+ end
39
+ end
40
+
41
+ describe '.write' do
42
+ #method not conducive to unit tests
43
+ end
44
+
45
+ describe '.get_fill_color' do
46
+ it 'should return the fill color of a particular style attribute' do
47
+ @cell.change_fill('000000')
48
+ @workbook.get_fill_color(@workbook.cell_xfs[@cell.style_index]).should == '000000'
49
+ end
50
+
51
+ it 'should return white (ffffff) if no fill color is specified in style' do
52
+ @workbook.get_fill_color(@workbook.cell_xfs[@cell.style_index]).should == 'ffffff'
53
+ end
54
+ end
55
+
56
+ describe '.is_date_format?' do
57
+
58
+ it 'should return true if number format = dd// yy// mm' do
59
+ @workbook.is_date_format?('dd// yy// mm').should == true
60
+ end
61
+
62
+ it 'should return true if number format = DD// YY// MM (uppercase)' do
63
+ @workbook.is_date_format?('DD// YY// MM').should == true
64
+ end
65
+
66
+ it 'should return false if number format = @' do
67
+ @workbook.is_date_format?('@').should == false
68
+ @workbook.is_date_format?('general').should == false
69
+ @workbook.is_date_format?('0.00e+00').should == false
70
+ end
71
+ end
72
+
73
+ end
@@ -0,0 +1,1789 @@
1
+ require 'rubygems'
2
+ require 'rubyXL'
3
+
4
+ describe RubyXL::Worksheet do
5
+ before do
6
+ @workbook = RubyXL::Workbook.new
7
+ @worksheet = RubyXL::Worksheet.new(@workbook)
8
+ @workbook.worksheets << @worksheet
9
+ (0..10).each do |i|
10
+ (0..10).each do |j|
11
+ @worksheet.add_cell(i, j, "#{i}:#{j}")
12
+ end
13
+ end
14
+
15
+ @old_cell = Marshal.load(Marshal.dump(@worksheet[0][0]))
16
+ @old_cell_value = @worksheet[0][0].value
17
+ @old_cell_formula = @worksheet[0][0].formula
18
+ end
19
+
20
+ describe '.extract_data' do
21
+ it 'should return a 2d array of just the cell values (without style or formula information)' do
22
+ data = @worksheet.extract_data()
23
+ data[0][0].should == '0:0'
24
+ data.size.should == @worksheet.sheet_data.size
25
+ data[0].size.should == @worksheet[0].size
26
+ end
27
+ end
28
+
29
+ describe '.get_table' do
30
+ it 'should return nil if table cannot be found with specified string' do
31
+ @worksheet.get_table('TEST').should be_nil
32
+ end
33
+
34
+ it 'should return nil if table cannot be found with specified headers' do
35
+ @worksheet.get_table(['TEST']).should be_nil
36
+ end
37
+
38
+ it 'should return a hash when given an array of headers it can find, where :table points to an array of hashes (rows), where each symbol is a column' do
39
+ headers = ["0:0", "0:1", "0:4"]
40
+ table_hash = @worksheet.get_table(headers)
41
+
42
+ table_hash[:table].size.should == 10
43
+ table_hash["0:0"].size.should == 10
44
+ table_hash["0:1"].size.should == 10
45
+ table_hash["0:4"].size.should == 10
46
+ end
47
+ end
48
+
49
+ describe '.change_row_fill' do
50
+ it 'should raise error if hex color code not passed' do
51
+ lambda {
52
+ @worksheet.change_row_fill(0, 'G')
53
+ }.should raise_error
54
+ end
55
+
56
+ it 'should raise error if hex color code includes # character' do
57
+ lambda {
58
+ @worksheet.change_row_fill(3,'#FFF000')
59
+ }.should raise_error
60
+ end
61
+
62
+ it 'should make row and cell fill colors equal hex color code passed' do
63
+ @worksheet.change_row_fill(0, '111111')
64
+ @worksheet.get_row_fill(0).should == '111111'
65
+ @worksheet[0][5].fill_color.should == '111111'
66
+ end
67
+
68
+ it 'should cause error if a negative argument is passed in' do
69
+ lambda {
70
+ @worksheet.change_row_fill(-1,'111111')
71
+ }.should raise_error
72
+ end
73
+
74
+ it 'should expand matrix to fit argument if nonnegative' do
75
+ @worksheet.sheet_data.size.should == 11
76
+ @worksheet.change_row_fill(11,'111111')
77
+ @worksheet.get_row_fill(11).should == '111111'
78
+ @worksheet.sheet_data.size.should == 12
79
+ end
80
+ end
81
+
82
+ describe '.change_row_font_name' do
83
+ it 'should make row and cell font names equal font name passed' do
84
+ @worksheet.change_row_font_name(0, 'Arial')
85
+ @worksheet.get_row_font_name(0).should == 'Arial'
86
+ @worksheet[0][5].font_name.should == 'Arial'
87
+ end
88
+
89
+ it 'should cause error if a negative argument is passed in' do
90
+ lambda {
91
+ @worksheet.change_row_font_name(-1,'Arial')
92
+ }.should raise_error
93
+ end
94
+
95
+ it 'should expand matrix to fit argument if nonnegative' do
96
+ @worksheet.sheet_data.size.should == 11
97
+ @worksheet.change_row_font_name(11, 'Arial')
98
+ @worksheet.get_row_font_name(11).should == "Arial"
99
+ @worksheet.sheet_data.size.should == 12
100
+ end
101
+ end
102
+
103
+ describe '.change_row_font_size' do
104
+ it 'should make row and cell font sizes equal font number passed' do
105
+ @worksheet.change_row_font_size(0, 20)
106
+ @worksheet.get_row_font_size(0).should == 20
107
+ @worksheet[0][5].font_size.should == 20
108
+ end
109
+
110
+ it 'should cause an error if a string passed' do
111
+ lambda {
112
+ @worksheet.change_row_font_size(0, '20')
113
+ }.should raise_error
114
+ end
115
+
116
+ it 'should cause error if a negative argument is passed in' do
117
+ lambda {
118
+ @worksheet.change_row_font_size(-1,20)
119
+ }.should raise_error
120
+ end
121
+
122
+ it 'should expand matrix to fit argument if nonnegative' do
123
+ @worksheet.sheet_data.size.should == 11
124
+ @worksheet.change_row_font_size(11,20)
125
+ @worksheet.get_row_font_size(11).should == 20
126
+ @worksheet.sheet_data.size.should == 12
127
+ end
128
+ end
129
+
130
+ describe '.change_row_font_color' do
131
+ it 'should make row and cell font colors equal to font color passed' do
132
+ @worksheet.change_row_font_color(0, '0f0f0f')
133
+ @worksheet.get_row_font_color(0).should == '0f0f0f'
134
+ @worksheet[0][5].font_color.should == '0f0f0f'
135
+ end
136
+
137
+ it 'should raise error if hex color code not passed' do
138
+ lambda {
139
+ @worksheet.change_row_font_color(0, 'G')
140
+ }.should raise_error
141
+ end
142
+
143
+ it 'should raise error if hex color code includes # character' do
144
+ lambda {
145
+ @worksheet.change_row_font_color(3,'#FFF000')
146
+ }.should raise_error
147
+ end
148
+
149
+ it 'should cause error if a negative argument is passed in' do
150
+ lambda {
151
+ @worksheet.change_row_font_color(-1,'0f0f0f')
152
+ }.should raise_error
153
+ end
154
+
155
+ it 'should expand matrix to fit argument if nonnegative' do
156
+ @worksheet.sheet_data.size.should == 11
157
+ @worksheet.change_row_font_color(11,'0f0f0f')
158
+ @worksheet.get_row_font_color(11).should == '0f0f0f'
159
+ @worksheet.sheet_data.size.should == 12
160
+ end
161
+ end
162
+
163
+ describe '.change_row_italics' do
164
+ it 'should make row and cell fonts italicized when true is passed' do
165
+ @worksheet.change_row_italics(0,true)
166
+ @worksheet.is_row_italicized(0).should == true
167
+ @worksheet[0][5].is_italicized.should == true
168
+ end
169
+
170
+ it 'should cause error if a negative argument is passed in' do
171
+ lambda {
172
+ @worksheet.change_row_italics(-1,false)
173
+ }.should raise_error
174
+ end
175
+
176
+ it 'should expand matrix to fit argument if nonnegative' do
177
+ @worksheet.sheet_data.size.should == 11
178
+ @worksheet.change_row_italics(11,true)
179
+ @worksheet.is_row_italicized(11).should == true
180
+ @worksheet.sheet_data.size.should == 12
181
+ end
182
+ end
183
+
184
+ describe '.change_row_bold' do
185
+ it 'should make row and cell fonts bolded when true is passed' do
186
+ @worksheet.change_row_bold(0,true)
187
+ @worksheet.is_row_bolded(0).should == true
188
+ @worksheet[0][5].is_bolded.should == true
189
+ end
190
+
191
+ it 'should cause error if a negative argument is passed in' do
192
+ lambda {
193
+ @worksheet.change_row_bold(-1,false)
194
+ }.should raise_error
195
+ end
196
+
197
+ it 'should expand matrix to fit argument if nonnegative' do
198
+ @worksheet.sheet_data.size.should == 11
199
+ @worksheet.change_row_bold(11,true)
200
+ @worksheet.is_row_bolded(11).should == true
201
+ @worksheet.sheet_data.size.should == 12
202
+ end
203
+ end
204
+
205
+ describe '.change_row_underline' do
206
+ it 'should make row and cell fonts underlined when true is passed' do
207
+ @worksheet.change_row_underline(0,true)
208
+ @worksheet.is_row_underlined(0).should == true
209
+ @worksheet[0][5].is_underlined.should == true
210
+ end
211
+
212
+ it 'should cause error if a negative argument is passed in' do
213
+ lambda {
214
+ @worksheet.change_row_underline(-1,false)
215
+ }.should raise_error
216
+ end
217
+
218
+ it 'should expand matrix to fit argument if nonnegative' do
219
+ @worksheet.sheet_data.size.should == 11
220
+ @worksheet.change_row_underline(11,true)
221
+ @worksheet.is_row_underlined(11).should == true
222
+ @worksheet.sheet_data.size.should == 12
223
+ end
224
+ end
225
+
226
+ describe '.change_row_strikethrough' do
227
+ it 'should make row and cell fonts struckthrough when true is passed' do
228
+ @worksheet.change_row_strikethrough(0,true)
229
+ @worksheet.is_row_struckthrough(0).should == true
230
+ @worksheet[0][5].is_struckthrough.should == true
231
+ end
232
+
233
+ it 'should cause error if a negative argument is passed in' do
234
+ lambda {
235
+ @worksheet.change_row_strikethrough(-1,false)
236
+ }.should raise_error
237
+ end
238
+
239
+ it 'should expand matrix to fit argument if nonnegative' do
240
+ @worksheet.sheet_data.size.should == 11
241
+ @worksheet.change_row_strikethrough(11,true)
242
+ @worksheet.is_row_struckthrough(11).should == true
243
+ @worksheet.sheet_data.size.should == 12
244
+ end
245
+ end
246
+
247
+ describe '.change_row_height' do
248
+ it 'should make row height match number which is passed' do
249
+ @worksheet.change_row_height(0,30.0002)
250
+ @worksheet.get_row_height(0).should == 30.0002
251
+ end
252
+
253
+ it 'should make row height a number equivalent of the string passed if it is a string which is a number' do
254
+ @worksheet.change_row_height(0,'30.0002')
255
+ @worksheet.get_row_height(0).should == 30.0002
256
+ end
257
+
258
+ it 'should cause error if a string which is not a number' do
259
+ lambda {
260
+ @worksheet.change_row_height(0,'TEST')
261
+ }.should raise_error
262
+ end
263
+
264
+ it 'should cause error if a negative argument is passed in' do
265
+ lambda {
266
+ @worksheet.change_row_height(-1,30)
267
+ }.should raise_error
268
+ end
269
+
270
+ it 'should expand matrix to fit argument if nonnegative' do
271
+ @worksheet.sheet_data.size.should == 11
272
+ @worksheet.change_row_height(11,30)
273
+ @worksheet.get_row_height(11).should == 30
274
+ @worksheet.sheet_data.size.should == 12
275
+ end
276
+ end
277
+
278
+ describe '.change_row_horizontal_alignment' do
279
+ it 'should cause row and cells to horizontally align as specified by the passed in string' do
280
+ @worksheet.change_row_horizontal_alignment(0,'center')
281
+ @worksheet.get_row_horizontal_alignment(0).should == 'center'
282
+ @worksheet[0][5].horizontal_alignment.should == 'center'
283
+ end
284
+
285
+ it 'should cause error if nil, "center", "justify", "left", "right", or "distributed" is not passed' do
286
+ lambda {
287
+ @worksheet.change_row_horizontal_alignment(0,'TEST')
288
+ }.should raise_error
289
+ end
290
+
291
+ it 'should cause error if a negative argument is passed in' do
292
+ lambda {
293
+ @worksheet.change_row_horizontal_alignment(-1,'center')
294
+ }.should raise_error
295
+ end
296
+
297
+ it 'should expand matrix to fit argument if nonnegative' do
298
+ @worksheet.sheet_data.size.should == 11
299
+ @worksheet.change_row_horizontal_alignment(11,'center')
300
+ @worksheet.get_row_horizontal_alignment(11).should == 'center'
301
+ @worksheet.sheet_data.size.should == 12
302
+ end
303
+ end
304
+
305
+ describe '.change_row_vertical_alignment' do
306
+ it 'should cause row and cells to vertically align as specified by the passed in string' do
307
+ @worksheet.change_row_vertical_alignment(0,'center')
308
+ @worksheet.get_row_vertical_alignment(0).should == 'center'
309
+ @worksheet[0][5].vertical_alignment.should == 'center'
310
+ end
311
+
312
+ it 'should cause error if nil, "center", "justify", "top", "bottom", or "distributed" is not passed' do
313
+ lambda {
314
+ @worksheet.change_row_vertical_alignment(0,'TEST')
315
+ }.should raise_error
316
+ end
317
+
318
+ it 'should cause error if a negative argument is passed in' do
319
+ lambda {
320
+ @worksheet.change_row_vertical_alignment(-1,'center')
321
+ }.should raise_error
322
+ end
323
+
324
+ it 'should expand matrix to fit argument if nonnegative' do
325
+ @worksheet.sheet_data.size.should == 11
326
+ @worksheet.change_row_vertical_alignment(11,'center')
327
+ @worksheet.get_row_vertical_alignment(11).should == 'center'
328
+ @worksheet.sheet_data.size.should == 12
329
+ end
330
+ end
331
+
332
+ describe '.change_row_border_top' do
333
+ it 'should cause row and cells to have border at top of specified weight' do
334
+ @worksheet.change_row_border_top(0, 'thin')
335
+ @worksheet.get_row_border_top(0).should == 'thin'
336
+ @worksheet[0][5].border_top.should == 'thin'
337
+ end
338
+
339
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
340
+ lambda {
341
+ @worksheet.change_row_border_top(0,'TEST')
342
+ }.should raise_error
343
+ end
344
+
345
+ it 'should cause error if a negative argument is passed in' do
346
+ lambda {
347
+ @worksheet.change_row_border_top(-1,'thin')
348
+ }.should raise_error
349
+ end
350
+
351
+ it 'should expand matrix to fit argument if nonnegative' do
352
+ @worksheet.sheet_data.size.should == 11
353
+ @worksheet.change_row_border_top(11,'thin')
354
+ @worksheet.get_row_border_top(11).should == 'thin'
355
+ @worksheet.sheet_data.size.should == 12
356
+ end
357
+ end
358
+
359
+ describe '.change_row_border_left' do
360
+ it 'should cause row and cells to have border at left of specified weight' do
361
+ @worksheet.change_row_border_left(0, 'thin')
362
+ @worksheet.get_row_border_left(0).should == 'thin'
363
+ @worksheet[0][5].border_left.should == 'thin'
364
+ end
365
+
366
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
367
+ lambda {
368
+ @worksheet.change_row_border_left(0,'TEST')
369
+ }.should raise_error
370
+ end
371
+
372
+ it 'should cause error if a negative argument is passed in' do
373
+ lambda {
374
+ @worksheet.change_row_border_left(-1,'thin')
375
+ }.should raise_error
376
+ end
377
+
378
+ it 'should expand matrix to fit argument if nonnegative' do
379
+ @worksheet.sheet_data.size.should == 11
380
+ @worksheet.change_row_border_left(11,'thin')
381
+ @worksheet.get_row_border_left(11).should == 'thin'
382
+ @worksheet.sheet_data.size.should == 12
383
+ end
384
+ end
385
+
386
+ describe '.change_row_border_right' do
387
+ it 'should cause row and cells to have border at right of specified weight' do
388
+ @worksheet.change_row_border_right(0, 'thin')
389
+ @worksheet.get_row_border_right(0).should == 'thin'
390
+ @worksheet[0][5].border_right.should == 'thin'
391
+ end
392
+
393
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
394
+ lambda {
395
+ @worksheet.change_row_border_right(0,'TEST')
396
+ }.should raise_error
397
+ end
398
+
399
+ it 'should cause error if a negative argument is passed in' do
400
+ lambda {
401
+ @worksheet.change_row_border_right(-1,'thin')
402
+ }.should raise_error
403
+ end
404
+
405
+ it 'should expand matrix to fit argument if nonnegative' do
406
+ @worksheet.sheet_data.size.should == 11
407
+ @worksheet.change_row_border_right(11,'thin')
408
+ @worksheet.get_row_border_right(11).should == 'thin'
409
+ @worksheet.sheet_data.size.should == 12
410
+ end
411
+ end
412
+
413
+ describe '.change_row_border_bottom' do
414
+ it 'should cause row to have border at bottom of specified weight' do
415
+ @worksheet.change_row_border_bottom(0, 'thin')
416
+ @worksheet.get_row_border_bottom(0).should == 'thin'
417
+ @worksheet[0][5].border_bottom.should == 'thin'
418
+ end
419
+
420
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
421
+ lambda {
422
+ @worksheet.change_row_border_bottom(0,'TEST')
423
+ }.should raise_error
424
+ end
425
+
426
+ it 'should cause error if a negative argument is passed in' do
427
+ lambda {
428
+ @worksheet.change_row_border_bottom(-1,'thin')
429
+ }.should raise_error
430
+ end
431
+
432
+ it 'should expand matrix to fit argument if nonnegative' do
433
+ @worksheet.sheet_data.size.should == 11
434
+ @worksheet.change_row_border_bottom(11,'thin')
435
+ @worksheet.get_row_border_bottom(11).should == 'thin'
436
+ @worksheet.sheet_data.size.should == 12
437
+ end
438
+ end
439
+
440
+ describe '.change_row_border_diagonal' do
441
+ it 'should cause row to have border at diagonal of specified weight' do
442
+ @worksheet.change_row_border_diagonal(0, 'thin')
443
+ @worksheet.get_row_border_diagonal(0).should == 'thin'
444
+ @worksheet[0][5].border_diagonal.should == 'thin'
445
+ end
446
+
447
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
448
+ lambda {
449
+ @worksheet.change_row_border_diagonal(0,'TEST')
450
+ }.should raise_error
451
+ end
452
+
453
+ it 'should cause error if a negative argument is passed in' do
454
+ lambda {
455
+ @worksheet.change_row_border_diagonal(-1,'thin')
456
+ }.should raise_error
457
+ end
458
+
459
+ it 'should expand matrix to fit argument if nonnegative' do
460
+ @worksheet.sheet_data.size.should == 11
461
+ @worksheet.change_row_border_diagonal(11,'thin')
462
+ @worksheet.get_row_border_diagonal(11).should == 'thin'
463
+ @worksheet.sheet_data.size.should == 12
464
+ end
465
+ end
466
+
467
+ describe '.change_column_font_name' do
468
+ it 'should cause column and cell font names to match string passed in' do
469
+ @worksheet.change_column_font_name(0, 'Arial')
470
+ @worksheet.get_column_font_name(0).should == 'Arial'
471
+ @worksheet[5][0].font_name.should == 'Arial'
472
+ end
473
+
474
+ it 'should cause error if a negative argument is passed in' do
475
+ lambda {
476
+ @worksheet.change_column_font_name(-1,'Arial')
477
+ }.should raise_error
478
+ end
479
+
480
+ it 'should expand matrix to fit argument if nonnegative' do
481
+ @worksheet.sheet_data[0].size.should == 11
482
+ @worksheet.change_column_font_name(11,'Arial')
483
+ @worksheet.get_column_font_name(11).should == 'Arial'
484
+ @worksheet.sheet_data[0].size.should == 12
485
+ end
486
+ end
487
+
488
+ describe '.change_column_font_size' do
489
+ it 'should make column and cell font sizes equal font number passed' do
490
+ @worksheet.change_column_font_size(0, 20)
491
+ @worksheet.get_column_font_size(0).should == 20
492
+ @worksheet[5][0].font_size.should == 20
493
+ end
494
+
495
+ it 'should cause an error if a string passed' do
496
+ lambda {
497
+ @worksheet.change_column_font_size(0, '20')
498
+ }.should raise_error
499
+ end
500
+
501
+ it 'should cause error if a negative argument is passed in' do
502
+ lambda {
503
+ @worksheet.change_column_font_size(-1,20)
504
+ }.should raise_error
505
+ end
506
+
507
+ it 'should expand matrix to fit argument if nonnegative'do
508
+ @worksheet.sheet_data[0].size.should == 11
509
+ @worksheet.change_column_font_size(11,20)
510
+ @worksheet.get_column_font_size(11).should == 20
511
+ @worksheet.sheet_data[0].size.should == 12
512
+ end
513
+ end
514
+
515
+ describe '.change_column_font_color' do
516
+ it 'should make column and cell font colors equal to font color passed' do
517
+ @worksheet.change_column_font_color(0, '0f0f0f')
518
+ @worksheet.get_column_font_color(0).should == '0f0f0f'
519
+ @worksheet[5][0].font_color.should == '0f0f0f'
520
+ end
521
+
522
+ it 'should raise error if hex color code not passed' do
523
+ lambda {
524
+ @worksheet.change_column_font_color(0, 'G')
525
+ }.should raise_error
526
+ end
527
+
528
+ it 'should raise error if hex color code includes # character' do
529
+ lambda {
530
+ @worksheet.change_column_font_color(0,'#FFF000')
531
+ }.should raise_error
532
+ end
533
+
534
+ it 'should cause error if a negative argument is passed in' do
535
+ lambda {
536
+ @worksheet.change_column_font_color(-1,'0f0f0f')
537
+ }.should raise_error
538
+ end
539
+
540
+ it 'should expand matrix to fit argument if nonnegative'do
541
+ @worksheet.sheet_data[0].size.should == 11
542
+ @worksheet.change_column_font_color(11,'0f0f0f')
543
+ @worksheet.get_column_font_color(11).should == '0f0f0f'
544
+ @worksheet.sheet_data[0].size.should == 12
545
+ end
546
+ end
547
+
548
+ describe '.change_column_italics' do
549
+ it 'should make column and cell fonts italicized when true is passed' do
550
+ @worksheet.change_column_italics(0,true)
551
+ @worksheet.is_column_italicized(0).should == true
552
+ @worksheet[5][0].is_italicized.should == true
553
+ end
554
+
555
+ it 'should cause error if a negative argument is passed in' do
556
+ lambda {
557
+ @worksheet.change_column_italicized(-1,false)
558
+ }.should raise_error
559
+ end
560
+
561
+ it 'should expand matrix to fit argument if nonnegative'do
562
+ @worksheet.sheet_data[0].size.should == 11
563
+ @worksheet.change_column_italics(11,true)
564
+ @worksheet.is_column_italicized(11).should == true
565
+ @worksheet.sheet_data[0].size.should == 12
566
+ end
567
+ end
568
+
569
+ describe '.change_column_bold' do
570
+ it 'should make column and cell fonts bolded when true is passed' do
571
+ @worksheet.change_column_bold(0,true)
572
+ @worksheet.is_column_bolded(0).should == true
573
+ @worksheet[5][0].is_bolded.should == true
574
+ end
575
+
576
+ it 'should cause error if a negative argument is passed in' do
577
+ lambda {
578
+ @worksheet.change_column_bold(-1,false)
579
+ }.should raise_error
580
+ end
581
+
582
+ it 'should expand matrix to fit argument if nonnegative'do
583
+ @worksheet.sheet_data[0].size.should == 11
584
+ @worksheet.change_column_bold(11,true)
585
+ @worksheet.is_column_bolded(11).should == true
586
+ @worksheet.sheet_data[0].size.should == 12
587
+ end
588
+ end
589
+
590
+ describe '.change_column_underline' do
591
+ it 'should make column and cell fonts underlined when true is passed' do
592
+ @worksheet.change_column_underline(0,true)
593
+ @worksheet.is_column_underlined(0).should == true
594
+ @worksheet[5][0].is_underlined.should == true
595
+ end
596
+
597
+ it 'should cause error if a negative argument is passed in' do
598
+ lambda {
599
+ @worksheet.change_column_underline(-1,false)
600
+ }.should raise_error
601
+ end
602
+
603
+ it 'should expand matrix to fit argument if nonnegative'do
604
+ @worksheet.sheet_data[0].size.should == 11
605
+ @worksheet.change_column_underline(11,true)
606
+ @worksheet.is_column_underlined(11).should == true
607
+ @worksheet.sheet_data[0].size.should == 12
608
+ end
609
+ end
610
+
611
+ describe '.change_column_strikethrough' do
612
+ it 'should make column and cell fonts struckthrough when true is passed' do
613
+ @worksheet.change_column_strikethrough(0,true)
614
+ @worksheet.is_column_struckthrough(0).should == true
615
+ @worksheet[5][0].is_struckthrough.should == true
616
+ end
617
+
618
+ it 'should cause error if a negative argument is passed in' do
619
+ lambda {
620
+ @worksheet.change_column_strikethrough(-1,false)
621
+ }.should raise_error
622
+ end
623
+
624
+ it 'should expand matrix to fit argument if nonnegative'do
625
+ @worksheet.sheet_data[0].size.should == 11
626
+ @worksheet.change_column_strikethrough(11,true)
627
+ @worksheet.is_column_struckthrough(11).should == true
628
+ @worksheet.sheet_data[0].size.should == 12
629
+ end
630
+ end
631
+
632
+ describe '.change_column_width' do
633
+ it 'should make column width match number which is passed' do
634
+ @worksheet.change_column_width(0,30.0002)
635
+ @worksheet.get_column_width(0).should == 30.0002
636
+ end
637
+
638
+ it 'should cause error if a negative argument is passed in' do
639
+ lambda {
640
+ @worksheet.change_column_width(-1,10)
641
+ }.should raise_error
642
+ end
643
+
644
+ it 'should expand matrix to fit argument if nonnegative'do
645
+ @worksheet.sheet_data[0].size.should == 11
646
+ @worksheet.change_column_width(11,30)
647
+ @worksheet.get_column_width(11).should == 30
648
+ @worksheet.sheet_data[0].size.should == 12
649
+ end
650
+ end
651
+
652
+ describe '.change_column_fill' do
653
+ it 'should raise error if hex color code not passed' do
654
+ lambda {
655
+ @worksheet.change_column_fill(0, 'G')
656
+ }.should raise_error
657
+ end
658
+
659
+ it 'should raise error if hex color code includes # character' do
660
+ lambda {
661
+ @worksheet.change_column_fill(3,'#FFF000')
662
+ }.should raise_error
663
+ end
664
+
665
+ it 'should make column and cell fill colors equal hex color code passed' do
666
+ @worksheet.change_column_fill(0, '111111')
667
+ @worksheet.get_column_fill(0).should == '111111'
668
+ @worksheet[5][0].fill_color.should == '111111'
669
+ end
670
+
671
+ it 'should cause error if a negative argument is passed in' do
672
+ lambda {
673
+ @worksheet.change_column_fill(-1,'111111')
674
+ }.should raise_error
675
+ end
676
+
677
+ it 'should expand matrix to fit argument if nonnegative'do
678
+ @worksheet.sheet_data[0].size.should == 11
679
+ @worksheet.change_column_fill(11,'111111')
680
+ @worksheet.get_column_fill(11).should == '111111'
681
+ @worksheet.sheet_data[0].size.should == 12
682
+ end
683
+ end
684
+
685
+ describe '.change_column_horizontal_alignment' do
686
+ it 'should cause column and cell to horizontally align as specified by the passed in string' do
687
+ @worksheet.change_column_horizontal_alignment(0,'center')
688
+ @worksheet.get_column_horizontal_alignment(0).should == 'center'
689
+ @worksheet[5][0].horizontal_alignment.should == 'center'
690
+ end
691
+
692
+ it 'should cause error if nil, "center", "justify", "left", "right", or "distributed" is not passed' do
693
+ lambda {
694
+ @worksheet.change_column_horizontal_alignment(0,'TEST')
695
+ }.should raise_error
696
+ end
697
+
698
+ it 'should cause error if a negative argument is passed in' do
699
+ lambda {
700
+ @worksheet.change_column_horizontal_alignment(-1,'center')
701
+ }.should raise_error
702
+ end
703
+
704
+ it 'should expand matrix to fit argument if nonnegative'do
705
+ @worksheet.sheet_data[0].size.should == 11
706
+ @worksheet.change_column_horizontal_alignment(11,'center')
707
+ @worksheet.get_column_horizontal_alignment(11).should == 'center'
708
+ @worksheet.sheet_data[0].size.should == 12
709
+ end
710
+ end
711
+
712
+ describe '.change_column_vertical_alignment' do
713
+ it 'should cause column and cell to vertically align as specified by the passed in string' do
714
+ @worksheet.change_column_vertical_alignment(0,'center')
715
+ @worksheet.get_column_vertical_alignment(0).should == 'center'
716
+ @worksheet[5][0].vertical_alignment.should == 'center'
717
+ end
718
+
719
+ it 'should cause error if nil, "center", "justify", "top", "bottom", or "distributed" is not passed' do
720
+ lambda {
721
+ @worksheet.change_column_vertical_alignment(0,'TEST')
722
+ }.should raise_error
723
+ end
724
+
725
+ it 'should cause error if a negative argument is passed in' do
726
+ lambda {
727
+ @worksheet.change_column_vertical_alignment(-1,'center')
728
+ }.should raise_error
729
+ end
730
+
731
+ it 'should expand matrix to fit argument if nonnegative'do
732
+ @worksheet.sheet_data[0].size.should == 11
733
+ @worksheet.change_column_vertical_alignment(11,'center')
734
+ @worksheet.get_column_vertical_alignment(11).should == 'center'
735
+ @worksheet.sheet_data[0].size.should == 12
736
+ end
737
+ end
738
+
739
+ describe '.change_column_border_top' do
740
+ it 'should cause column and cells within to have border at top of specified weight' do
741
+ @worksheet.change_column_border_top(0, 'thin')
742
+ @worksheet.get_column_border_top(0).should == 'thin'
743
+ @worksheet[5][0].border_top.should == 'thin'
744
+ end
745
+
746
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
747
+ lambda {
748
+ @worksheet.change_column_border_top(0,'TEST')
749
+ }.should raise_error
750
+ end
751
+
752
+ it 'should cause error if a negative argument is passed in' do
753
+ lambda {
754
+ @worksheet.change_column_border_top(-1,'thin')
755
+ }.should raise_error
756
+ end
757
+
758
+ it 'should expand matrix to fit argument if nonnegative'do
759
+ @worksheet.sheet_data[0].size.should == 11
760
+ @worksheet.change_column_border_top(11,'thin')
761
+ @worksheet.get_column_border_top(11).should == 'thin'
762
+ @worksheet.sheet_data[0].size.should == 12
763
+ end
764
+ end
765
+
766
+ describe '.change_column_border_left' do
767
+ it 'should cause column and cells within to have border at left of specified weight' do
768
+ @worksheet.change_column_border_left(0, 'thin')
769
+ @worksheet.get_column_border_left(0).should == 'thin'
770
+ @worksheet[5][0].border_left.should == 'thin'
771
+ end
772
+
773
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
774
+ lambda {
775
+ @worksheet.change_column_border_left(0,'TEST')
776
+ }.should raise_error
777
+ end
778
+
779
+ it 'should cause error if a negative argument is passed in' do
780
+ lambda {
781
+ @worksheet.change_column_border_left(-1,'thin')
782
+ }.should raise_error
783
+ end
784
+
785
+ it 'should expand matrix to fit argument if nonnegative' do
786
+ @worksheet.sheet_data[0].size.should == 11
787
+ @worksheet.change_column_border_left(11,'thin')
788
+ @worksheet.get_column_border_left(11).should == 'thin'
789
+ @worksheet.sheet_data[0].size.should == 12
790
+ end
791
+ end
792
+
793
+ describe '.change_column_border_right' do
794
+ it 'should cause column and cells within to have border at right of specified weight' do
795
+ @worksheet.change_column_border_right(0, 'thin')
796
+ @worksheet.get_column_border_right(0).should == 'thin'
797
+ @worksheet[5][0].border_right.should == 'thin'
798
+ end
799
+
800
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
801
+ lambda {
802
+ @worksheet.change_column_border_right(0,'TEST')
803
+ }.should raise_error
804
+ end
805
+
806
+ it 'should cause error if a negative argument is passed in' do
807
+ lambda {
808
+ @worksheet.change_column_border_right(-1,'thin')
809
+ }.should raise_error
810
+ end
811
+
812
+ it 'should expand matrix to fit argument if nonnegative'do
813
+ @worksheet.sheet_data[0].size.should == 11
814
+ @worksheet.change_column_border_right(11,'thin')
815
+ @worksheet.get_column_border_right(11).should == 'thin'
816
+ @worksheet.sheet_data[0].size.should == 12
817
+ end
818
+ end
819
+
820
+ describe '.change_column_border_bottom' do
821
+ it 'should cause column and cells within to have border at bottom of specified weight' do
822
+ @worksheet.change_column_border_bottom(0, 'thin')
823
+ @worksheet.get_column_border_bottom(0).should == 'thin'
824
+ @worksheet[5][0].border_bottom.should == 'thin'
825
+ end
826
+
827
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
828
+ lambda {
829
+ @worksheet.change_column_border_bottom(0,'TEST')
830
+ }.should raise_error
831
+ end
832
+
833
+ it 'should cause error if a negative argument is passed in' do
834
+ lambda {
835
+ @worksheet.change_column_border_bottom(-1,'thin')
836
+ }.should raise_error
837
+ end
838
+
839
+ it 'should expand matrix to fit argument if nonnegative'do
840
+ @worksheet.sheet_data[0].size.should == 11
841
+ @worksheet.change_column_border_bottom(11,'thin')
842
+ @worksheet.get_column_border_bottom(11).should == 'thin'
843
+ @worksheet.sheet_data[0].size.should == 12
844
+ end
845
+ end
846
+
847
+ describe '.change_column_border_diagonal' do
848
+ it 'should cause column and cells within to have border at diagonal of specified weight' do
849
+ @worksheet.change_column_border_diagonal(0, 'thin')
850
+ @worksheet.get_column_border_diagonal(0).should == 'thin'
851
+ @worksheet[5][0].border_diagonal.should == 'thin'
852
+ end
853
+
854
+ it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
855
+ lambda {
856
+ @worksheet.change_column_border_diagonal(0,'TEST')
857
+ }.should raise_error
858
+ end
859
+
860
+ it 'should cause error if a negative argument is passed in' do
861
+ lambda {
862
+ @worksheet.change_column_border_diagonal(-1,'thin')
863
+ }.should raise_error
864
+ end
865
+
866
+ it 'should expand matrix to fit argument if nonnegative' do
867
+ @worksheet.sheet_data[0].size.should == 11
868
+ @worksheet.change_column_border_diagonal(11,'thin')
869
+ @worksheet.get_column_border_diagonal(11).should == 'thin'
870
+ @worksheet.sheet_data[0].size.should == 12
871
+ end
872
+ end
873
+
874
+ describe '.merge_cells' do
875
+ it 'should merge cells in any valid range specified by indices' do
876
+ @worksheet.merge_cells(0, 0, 1, 1)
877
+ @worksheet.merged_cells.collect{ |r| r.to_s }.should == ["A1:B2"]
878
+ end
879
+ end
880
+
881
+ describe '.add_cell' do
882
+ it 'should add new cell where specified, even if a cell is already there (default)' do
883
+ @worksheet.add_cell(0,0,'TEST')
884
+ @worksheet[0][0].value.should_not == @old_cell_value
885
+ @worksheet[0][0].value.should == 'TEST'
886
+ end
887
+
888
+ it 'should add new cell where specified with formula, even if a cell is already there (default)' do
889
+ @worksheet.add_cell(0,0,'','SUM(A2:A10)')
890
+ @worksheet[0][0].value.should_not == @old_cell_value
891
+ @worksheet[0][0].formula.should_not == @old_cell_formula
892
+ @worksheet[0][0].value.should == ''
893
+ @worksheet[0][0].formula.should == 'SUM(A2:A10)'
894
+ end
895
+
896
+ it 'should not overwrite when a cell is present when overwrite is specified to be false' do
897
+ @worksheet.add_cell(0,0,'TEST','B2',false)
898
+ @worksheet[0][0].value.should == @old_cell_value
899
+ @worksheet[0][0].formula.should == @old_cell_formula
900
+ end
901
+
902
+ it 'should still add a new cell when there is no cell to be overwritten' do
903
+ @worksheet.add_cell(11,11,'TEST','B2',false)
904
+ @worksheet[11][11].value.should == 'TEST'
905
+ @worksheet[11][11].formula.should == 'B2'
906
+ end
907
+
908
+ it 'should cause error if a negative argument is passed in' do
909
+ lambda {
910
+ @worksheet.add_cell(-1,-1,'')
911
+ }.should raise_error
912
+ end
913
+ end
914
+
915
+ describe '.add_cell_obj' do
916
+ it 'should add already created cell object to worksheet, even if a cell is already there (default)' do
917
+ new_cell = RubyXL::Cell.new(@worksheet,0,0,'TEST','B2')
918
+ @worksheet.add_cell_obj(new_cell)
919
+ @worksheet[0][0].value.should_not == @old_cell_value
920
+ @worksheet[0][0].formula.should_not == @old_cell_formula
921
+ @worksheet[0][0].value.should == 'TEST'
922
+ @worksheet[0][0].formula.should == 'B2'
923
+ end
924
+
925
+ it 'should not add already created cell object to already occupied cell if overwrite is false' do
926
+ new_cell = RubyXL::Cell.new(@worksheet,0,0,'TEST','B2')
927
+ @worksheet.add_cell_obj(new_cell,false)
928
+ @worksheet[0][0].value.should == @old_cell_value
929
+ @worksheet[0][0].formula.should == @old_cell_formula
930
+ end
931
+
932
+ it 'should cause error if a negative argument is passed in' do
933
+ lambda {
934
+ @worksheet.add_cell_obj(-1)
935
+ }.should raise_error
936
+ end
937
+
938
+ it 'should expand matrix to fit argument if nonnegative' do
939
+ @worksheet.sheet_data.size.should == 11
940
+ new_cell = RubyXL::Cell.new(@worksheet,11,11,'TEST','B2')
941
+ @worksheet.add_cell_obj(new_cell)
942
+ @worksheet.sheet_data.size.should == 12
943
+ end
944
+ end
945
+
946
+ describe '.delete_row' do
947
+ it 'should delete a row at index specified, "pushing" everything else "up"' do
948
+ @worksheet.delete_row(0)
949
+ @worksheet[0][0].value.should == "1:0"
950
+ @worksheet[0][0].formula.should be_nil
951
+ @worksheet[0][0].row.should == 0
952
+ @worksheet[0][0].column.should == 0
953
+ end
954
+
955
+ it 'should delete a row at index specified, adjusting styles for other rows' do
956
+ @worksheet.change_row_font_name(1,"Courier")
957
+ @worksheet.delete_row(0)
958
+ @worksheet.get_row_font_name(0).should == "Courier"
959
+ end
960
+
961
+ it 'should preserve (rather than fix) formulas that reference cells in "pushed up" rows' do
962
+ @worksheet.add_cell(11,0,nil,'SUM(A1:A10)')
963
+ @worksheet.delete_row(0)
964
+ @worksheet[10][0].formula.should == 'SUM(A1:A10)'
965
+ end
966
+
967
+ it 'should cause error if a negative argument is passed in' do
968
+ lambda {
969
+ @worksheet.delete_row(-1)
970
+ }.should raise_error
971
+ end
972
+ end
973
+
974
+ describe '.insert_row' do
975
+ it 'should insert a row at index specified, "pushing" everything else "down"' do
976
+ @worksheet.insert_row(0)
977
+ @worksheet[0][0].should be_nil
978
+ @worksheet[1][0].value.should == @old_cell_value
979
+ @worksheet[1][0].formula.should == @old_cell_formula
980
+ end
981
+
982
+ it 'should insert a row at index specified, copying styles from row "above"' do
983
+ @worksheet.change_row_font_name(0,'Courier')
984
+ @worksheet.insert_row(1)
985
+ @worksheet.get_row_font_name(1).should == 'Courier'
986
+ end
987
+
988
+ it 'should preserve (rather than fix) formulas that reference cells "pushed down" rows' do
989
+ @worksheet.add_cell(5,0,nil,'SUM(A1:A4)')
990
+ @worksheet.insert_row(0)
991
+ @worksheet[6][0].formula.should == 'SUM(A1:A4)'
992
+ end
993
+
994
+ it 'should cause error if a negative argument is passed in' do
995
+ lambda {
996
+ @worksheet.insert_row(-1)
997
+ }.should raise_error
998
+ end
999
+
1000
+ it 'should expand matrix to fit argument if nonnegative' do
1001
+ @worksheet.sheet_data.size.should == 11
1002
+ @worksheet.insert_row(11)
1003
+ @worksheet.sheet_data.size.should == 13
1004
+ end
1005
+ end
1006
+
1007
+ describe '.delete_column' do
1008
+ it 'should delete a column at index specified, "pushing" everything else "left"' do
1009
+ @worksheet.delete_column(0)
1010
+ @worksheet[0][0].value.should == "0:1"
1011
+ @worksheet[0][0].formula.should be_nil
1012
+ @worksheet[0][0].row.should == 0
1013
+ @worksheet[0][0].column.should == 0
1014
+ end
1015
+
1016
+ it 'should delete a column at index specified, "pushing" styles "left"' do
1017
+ @worksheet.change_column_font_name(1,"Courier")
1018
+ @worksheet.delete_column(0)
1019
+ @worksheet.get_column_font_name(0).should == "Courier"
1020
+ end
1021
+
1022
+ it 'should preserve (rather than fix) formulas that reference cells in "pushed left" columns' do
1023
+ @worksheet.add_cell(0,4,nil,'SUM(A1:D1)')
1024
+ @worksheet.delete_column(0)
1025
+ @worksheet[0][3].formula.should == 'SUM(A1:D1)'
1026
+ end
1027
+
1028
+ it 'should cause error if negative argument is passed in' do
1029
+ lambda {
1030
+ @worksheet.delete_column(-1)
1031
+ }.should raise_error
1032
+ end
1033
+ end
1034
+
1035
+ describe '.insert_column' do
1036
+ it 'should insert a column at index specified, "pushing" everything else "right"' do
1037
+ @worksheet.insert_column(0)
1038
+ @worksheet[0][0].should be_nil
1039
+ @worksheet[0][1].value.should == @old_cell_value
1040
+ @worksheet[0][1].formula.should == @old_cell_formula
1041
+ end
1042
+
1043
+ it 'should insert a column at index specified, copying styles from column to "left"' do
1044
+ @worksheet.change_column_font_name(0,'Courier')
1045
+ @worksheet.insert_column(1)
1046
+ @worksheet.get_column_font_name(1).should == 'Courier'
1047
+ end
1048
+
1049
+ it 'should insert a column at 0 without copying any styles, when passed 0 as column index' do
1050
+ @worksheet.change_column_font_name(0, 'Courier')
1051
+ @worksheet.insert_column(0)
1052
+ @worksheet.get_column_font_name(0).should == 'Verdana' #not courier
1053
+ end
1054
+
1055
+ it 'should preserve (rather than fix) formulas that reference cells in "pushed right" column' do
1056
+ @worksheet.add_cell(0,5,nil,'SUM(A1:D1)')
1057
+ @worksheet.insert_column(0)
1058
+ @worksheet[0][6].formula.should == 'SUM(A1:D1)'
1059
+ end
1060
+
1061
+ it 'should cause error if a negative argument is passed in' do
1062
+ lambda {
1063
+ @worksheet.insert_column(-1)
1064
+ }.should raise_error
1065
+ end
1066
+
1067
+ it 'should expand matrix to fit argument if nonnegative' do
1068
+ @worksheet.sheet_data[0].size.should == 11
1069
+ @worksheet.insert_column(11)
1070
+ @worksheet.sheet_data[0].size.should == 13
1071
+ end
1072
+ end
1073
+
1074
+ describe '.insert_cell' do
1075
+ it 'should simply add a cell if no shift argument is specified' do
1076
+ @worksheet.insert_cell(0,0,'test')
1077
+ @worksheet[0][0].value.should == 'test'
1078
+ @worksheet[0][1].value.should == '0:1'
1079
+ @worksheet[1][0].value.should == '1:0'
1080
+ end
1081
+
1082
+ it 'should shift cells to the right if :right is specified' do
1083
+ @worksheet.insert_cell(0,0,'test',nil,:right)
1084
+ @worksheet[0][0].value.should == 'test'
1085
+ @worksheet[0][1].value.should == '0:0'
1086
+ @worksheet[1][0].value.should == '1:0'
1087
+ end
1088
+
1089
+ it 'should shift cells down if :down is specified' do
1090
+ @worksheet.insert_cell(0,0,'test',nil,:down)
1091
+ @worksheet[0][0].value.should == 'test'
1092
+ @worksheet[0][1].value.should == '0:1'
1093
+ @worksheet[1][0].value.should == '0:0'
1094
+ end
1095
+
1096
+ it 'should cause error if shift argument is specified whcih is not :right or :down' do
1097
+ lambda {
1098
+ @worksheet.insert_cell(0,0,'test',nil,:up)
1099
+ }.should raise_error
1100
+ end
1101
+
1102
+ it 'should cause error if a negative argument is passed in' do
1103
+ lambda {
1104
+ @worksheet.insert_cell(-1,-1)
1105
+ }.should raise_error
1106
+ end
1107
+ end
1108
+
1109
+ describe '.delete_cell' do
1110
+ it 'should make a cell nil if no shift argument specified' do
1111
+ deleted = @worksheet.delete_cell(0,0)
1112
+ @worksheet[0][0].should be_nil
1113
+ @old_cell.inspect.should == deleted.inspect
1114
+ end
1115
+
1116
+ it 'should return nil if a cell which is out of range is specified' do
1117
+ @worksheet.delete_cell(12,12).should be_nil
1118
+ end
1119
+
1120
+ it 'should cause error if a negative argument is passed in' do
1121
+ lambda {
1122
+ @worksheet.delete_cell(-1,-1)
1123
+ }.should raise_error
1124
+ end
1125
+
1126
+ it 'should shift cells to the right of the deleted cell left if :left is specified' do
1127
+ @worksheet.delete_cell(0,0,:left)
1128
+ @worksheet[0][0].value.should == '0:1'
1129
+ end
1130
+
1131
+ it 'should shift cells below the deleted cell up if :up is specified' do
1132
+ @worksheet.delete_cell(0,0,:up)
1133
+ @worksheet[0][0].value.should == '1:0'
1134
+ end
1135
+
1136
+ it 'should cause en error if an argument other than :left, :up, or nil is specified for shift' do
1137
+ lambda {
1138
+ @worksheet.delete_cell(0,0,:down)
1139
+ }.should raise_error
1140
+ end
1141
+ end
1142
+
1143
+ describe '.get_row_fill' do
1144
+ it 'should return white (ffffff) if no fill color specified for row' do
1145
+ @worksheet.get_row_fill(0).should == 'ffffff'
1146
+ end
1147
+
1148
+ it 'should correctly reflect fill color if specified for row' do
1149
+ @worksheet.change_row_fill(0, '000000')
1150
+ @worksheet.get_row_fill(0).should == '000000'
1151
+ end
1152
+
1153
+ it 'should return nil if a row which does not exist is passed in' do
1154
+ @worksheet.get_row_fill(11).should be_nil
1155
+ end
1156
+
1157
+ it 'should cause error if a negative argument is passed in' do
1158
+ lambda {
1159
+ @worksheet.get_row_fill(-1)
1160
+ }.should raise_error
1161
+ end
1162
+ end
1163
+
1164
+ describe '.get_row_font_name' do
1165
+ it 'should correctly reflect font name for row' do
1166
+ @worksheet.change_row_font_name(0,'Courier')
1167
+ @worksheet.get_row_font_name(0).should == 'Courier'
1168
+ end
1169
+
1170
+ it 'should cause error if a negative argument is passed in' do
1171
+ lambda {
1172
+ @worksheet.get_row_font_name(-1)
1173
+ }.should raise_error
1174
+ end
1175
+
1176
+ it 'should return nil if a (nonnegative) row which does not exist is passed in' do
1177
+ @worksheet.get_row_font_name(11).should be_nil
1178
+ end
1179
+ end
1180
+
1181
+ describe '.get_row_font_size' do
1182
+ it 'should correctly reflect font size for row' do
1183
+ @worksheet.change_row_font_size(0,30)
1184
+ @worksheet.get_row_font_size(0).should == 30
1185
+ end
1186
+
1187
+ it 'should cause error if a negative argument is passed in' do
1188
+ lambda {
1189
+ @worksheet.get_row_font_size(-1)
1190
+ }.should raise_error
1191
+ end
1192
+
1193
+ it 'should return nil if a (nonnegative) row which does not exist is passed in' do
1194
+ @worksheet.get_row_font_size(11).should be_nil
1195
+ end
1196
+ end
1197
+
1198
+ describe '.get_row_font_color' do
1199
+ it 'should correctly reflect font color for row' do
1200
+ @worksheet.change_row_font_color(0,'0f0f0f')
1201
+ @worksheet.get_row_font_color(0).should == '0f0f0f'
1202
+ end
1203
+
1204
+ it 'should cause error if a negative argument is passed in' do
1205
+ lambda {
1206
+ @worksheet.get_row_font_color(-1)
1207
+ }.should raise_error
1208
+ end
1209
+
1210
+ it 'should return nil if a (nonnegative) row which does not exist is passed in' do
1211
+ @worksheet.get_row_font_color(11).should be_nil
1212
+ end
1213
+ end
1214
+
1215
+ describe '.is_row_italicized' do
1216
+ it 'should correctly return whether row is italicized' do
1217
+ @worksheet.change_row_italics(0,true)
1218
+ @worksheet.is_row_italicized(0).should == true
1219
+ end
1220
+
1221
+ it 'should cause error if a negative argument is passed in' do
1222
+ lambda {
1223
+ @worksheet.is_row_italicized(-1)
1224
+ }.should raise_error
1225
+ end
1226
+
1227
+ it 'should return nil if a (nonnegative) row which does not exist is passed in' do
1228
+ @worksheet.is_row_italicized(11).should be_nil
1229
+ end
1230
+ end
1231
+
1232
+ describe '.is_row_bolded' do
1233
+ it 'should correctly return whether row is bolded' do
1234
+ @worksheet.change_row_bold(0,true)
1235
+ @worksheet.is_row_bolded(0).should == true
1236
+ end
1237
+
1238
+ it 'should cause error if a negative argument is passed in' do
1239
+ lambda {
1240
+ @worksheet.is_row_bolded(-1)
1241
+ }.should raise_error
1242
+ end
1243
+
1244
+ it 'should return nil if a (nonnegative) row which does not exist is passed in' do
1245
+ @worksheet.is_row_bolded(11).should be_nil
1246
+ end
1247
+ end
1248
+
1249
+ describe '.is_row_underlined' do
1250
+ it 'should correctly return whether row is underlined' do
1251
+ @worksheet.change_row_underline(0,true)
1252
+ @worksheet.is_row_underlined(0).should == true
1253
+ end
1254
+
1255
+ it 'should cause error if a negative argument is passed in' do
1256
+ lambda {
1257
+ @worksheet.is_row_underlined(-1)
1258
+ }.should raise_error
1259
+ end
1260
+
1261
+ it 'should return nil if a (nonnegative) row which does not exist is passed in' do
1262
+ @worksheet.is_row_underlined(11).should be_nil
1263
+ end
1264
+ end
1265
+
1266
+ describe '.is_row_struckthrough' do
1267
+ it 'should correctly return whether row is struckthrough' do
1268
+ @worksheet.change_row_strikethrough(0,true)
1269
+ @worksheet.is_row_struckthrough(0).should == true
1270
+ end
1271
+
1272
+ it 'should cause error if a negative argument is passed in' do
1273
+ lambda {
1274
+ @worksheet.is_row_struckthrough(-1)
1275
+ }.should raise_error
1276
+ end
1277
+
1278
+ it 'should return nil if a (nonnegative) row which does not exist is passed in' do
1279
+ @worksheet.is_row_struckthrough(11).should be_nil
1280
+ end
1281
+ end
1282
+
1283
+ describe '.get_row_height' do
1284
+ it 'should return 13 if no height specified for row' do
1285
+ @worksheet.get_row_height(0).should == 13
1286
+ end
1287
+
1288
+ it 'should correctly reflect height if specified for row' do
1289
+ @worksheet.change_row_height(0, 30)
1290
+ @worksheet.get_row_height(0).should == 30
1291
+ end
1292
+
1293
+ it 'should return nil if a row which does not exist is passed in' do
1294
+ @worksheet.get_row_height(11).should be_nil
1295
+ end
1296
+
1297
+ it 'should cause error if a negative argument is passed in' do
1298
+ lambda {
1299
+ @worksheet.get_row_height(-1)
1300
+ }.should raise_error
1301
+ end
1302
+ end
1303
+
1304
+ describe '.get_row_horizontal_alignment' do
1305
+ it 'should return nil if no alignment specified for row' do
1306
+ @worksheet.get_row_horizontal_alignment(0).should be_nil
1307
+ end
1308
+
1309
+ it 'should return nil if a row which does not exist is passed in' do
1310
+ @worksheet.get_row_horizontal_alignment(11).should be_nil
1311
+ end
1312
+
1313
+ it 'should cause error if a negative argument is passed in' do
1314
+ lambda {
1315
+ @worksheet.get_row_horizontal_alignment(-1)
1316
+ }.should raise_error
1317
+ end
1318
+
1319
+ it 'should return correct horizontal alignment if it is set for that row' do
1320
+ @worksheet.change_row_horizontal_alignment(0, 'center')
1321
+ @worksheet.get_row_horizontal_alignment(0).should == 'center'
1322
+ end
1323
+ end
1324
+
1325
+ describe '.get_row_vertical_alignment' do
1326
+ it 'should return nil if no alignment specified for row' do
1327
+ @worksheet.get_row_vertical_alignment(0).should be_nil
1328
+ end
1329
+
1330
+ it 'should return nil if a row which does not exist is passed in' do
1331
+ @worksheet.get_row_vertical_alignment(11).should be_nil
1332
+ end
1333
+
1334
+ it 'should cause error if a negative argument is passed in' do
1335
+ lambda {
1336
+ @worksheet.get_row_vertical_alignment(-1)
1337
+ }.should raise_error
1338
+ end
1339
+
1340
+ it 'should return correct vertical alignment if it is set for that row' do
1341
+ @worksheet.change_row_vertical_alignment(0, 'center')
1342
+ @worksheet.get_row_vertical_alignment(0).should == 'center'
1343
+ end
1344
+ end
1345
+
1346
+ describe '.get_row_border_top' do
1347
+ it 'should return nil if no border is specified for that row in that direction' do
1348
+ @worksheet.get_row_border_top(0).should be_nil
1349
+ end
1350
+
1351
+ it 'should return type of border that this row has on top' do
1352
+ @worksheet.change_row_border_top(0,'thin')
1353
+ @worksheet.get_row_border_top(0).should == 'thin'
1354
+ end
1355
+
1356
+ it 'should cause error if a negative argument is passed in' do
1357
+ lambda {
1358
+ @worksheet.get_row_border_top(-1)
1359
+ }.should raise_error
1360
+ end
1361
+
1362
+ it 'should return nil if a row which does not exist is passed in' do
1363
+ @worksheet.get_row_border_top(11).should be_nil
1364
+ end
1365
+ end
1366
+
1367
+ describe '.get_row_border_left' do
1368
+ it 'should return nil if no border is specified for that row in that direction' do
1369
+ @worksheet.get_row_border_left(0).should be_nil
1370
+ end
1371
+
1372
+ it 'should return type of border that this row has on left' do
1373
+ @worksheet.change_row_border_left(0,'thin')
1374
+ @worksheet.get_row_border_left(0).should == 'thin'
1375
+ end
1376
+
1377
+ it 'should cause error if a negative argument is passed in' do
1378
+ lambda {
1379
+ @worksheet.get_row_border_left(-1)
1380
+ }.should raise_error
1381
+ end
1382
+
1383
+ it 'should return nil if a row which does not exist is passed in' do
1384
+ @worksheet.get_row_border_left(11).should be_nil
1385
+ end
1386
+ end
1387
+
1388
+ describe '.get_row_border_right' do
1389
+ it 'should return nil if no border is specified for that row in that direction' do
1390
+ @worksheet.get_row_border_right(0).should be_nil
1391
+ end
1392
+
1393
+ it 'should return type of border that this row has on right' do
1394
+ @worksheet.change_row_border_right(0,'thin')
1395
+ @worksheet.get_row_border_right(0).should == 'thin'
1396
+ end
1397
+
1398
+ it 'should cause error if a negative argument is passed in' do
1399
+ lambda {
1400
+ @worksheet.get_row_border_right(-1)
1401
+ }.should raise_error
1402
+ end
1403
+
1404
+ it 'should return nil if a row which does not exist is passed in' do
1405
+ @worksheet.get_row_border_right(11).should be_nil
1406
+ end
1407
+ end
1408
+
1409
+
1410
+ describe '.get_row_border_bottom' do
1411
+ it 'should return nil if no border is specified for that row in that direction' do
1412
+ @worksheet.get_row_border_bottom(0).should be_nil
1413
+ end
1414
+
1415
+ it 'should return type of border that this row has on bottom' do
1416
+ @worksheet.change_row_border_bottom(0,'thin')
1417
+ @worksheet.get_row_border_bottom(0).should == 'thin'
1418
+ end
1419
+
1420
+ it 'should cause error if a negative argument is passed in' do
1421
+ lambda {
1422
+ @worksheet.get_row_border_bottom(-1)
1423
+ }.should raise_error
1424
+ end
1425
+
1426
+ it 'should return nil if a row which does not exist is passed in' do
1427
+ @worksheet.get_row_border_bottom(11).should be_nil
1428
+ end
1429
+ end
1430
+
1431
+ describe '.get_row_border_diagonal' do
1432
+ it 'should return nil if no border is specified for that row in that direction' do
1433
+ @worksheet.get_row_border_diagonal(0).should be_nil
1434
+ end
1435
+
1436
+ it 'should return type of border that this row has on diagonal' do
1437
+ @worksheet.change_row_border_diagonal(0,'thin')
1438
+ @worksheet.get_row_border_diagonal(0).should == 'thin'
1439
+ end
1440
+
1441
+ it 'should cause error if a negative argument is passed in' do
1442
+ lambda {
1443
+ @worksheet.get_row_border_diagonal(-1)
1444
+ }.should raise_error
1445
+ end
1446
+
1447
+ it 'should return nil if a row which does not exist is passed in' do
1448
+ @worksheet.get_row_border_diagonal(11).should be_nil
1449
+ end
1450
+ end
1451
+
1452
+ describe '.get_column_font_name' do
1453
+ it 'should correctly reflect font name for column' do
1454
+ @worksheet.change_column_font_name(0,'Courier')
1455
+ @worksheet.get_column_font_name(0).should == 'Courier'
1456
+ end
1457
+
1458
+ it 'should cause error if a negative argument is passed in' do
1459
+ lambda {
1460
+ @worksheet.get_column_font_name(-1)
1461
+ }.should raise_error
1462
+ end
1463
+
1464
+ it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1465
+ @worksheet.get_column_font_name(11).should be_nil
1466
+ end
1467
+ end
1468
+
1469
+ describe '.get_column_font_size' do
1470
+ it 'should correctly reflect font size for column' do
1471
+ @worksheet.change_column_font_size(0,30)
1472
+ @worksheet.get_column_font_size(0).should == 30
1473
+ end
1474
+
1475
+ it 'should cause error if a negative argument is passed in' do
1476
+ lambda {
1477
+ @worksheet.get_column_font_size(-1)
1478
+ }.should raise_error
1479
+ end
1480
+
1481
+ it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1482
+ @worksheet.get_column_font_size(11).should be_nil
1483
+ end
1484
+ end
1485
+
1486
+ describe '.get_column_font_color' do
1487
+ it 'should correctly reflect font color for column' do
1488
+ @worksheet.change_column_font_color(0,'0f0f0f')
1489
+ @worksheet.get_column_font_color(0).should == '0f0f0f'
1490
+ end
1491
+
1492
+ it 'should cause error if a negative argument is passed in' do
1493
+ lambda {
1494
+ @worksheet.get_column_font_color(-1)
1495
+ }.should raise_error
1496
+ end
1497
+
1498
+ it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1499
+ @worksheet.get_column_font_color(11).should be_nil
1500
+ end
1501
+
1502
+ it 'should return black (000000) if no rgb font color is specified' do
1503
+ @worksheet.get_column_font_color(0).should == '000000'
1504
+ end
1505
+ end
1506
+
1507
+ describe '.is_column_italicized' do
1508
+ it 'should correctly return whether column is italicized' do
1509
+ @worksheet.change_column_italics(0,true)
1510
+ @worksheet.is_column_italicized(0).should == true
1511
+ end
1512
+
1513
+ it 'should cause error if a negative argument is passed in' do
1514
+ lambda {
1515
+ @worksheet.is_column_italicized(-1)
1516
+ }.should raise_error
1517
+ end
1518
+
1519
+ it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1520
+ @worksheet.is_column_italicized(11).should be_nil
1521
+ end
1522
+ end
1523
+
1524
+ describe '.is_column_bolded' do
1525
+ it 'should correctly return whether column is bolded' do
1526
+ @worksheet.change_column_bold(0,true)
1527
+ @worksheet.is_column_bolded(0).should == true
1528
+ end
1529
+
1530
+ it 'should cause error if a negative argument is passed in' do
1531
+ lambda {
1532
+ @worksheet.is_column_bolded(-1)
1533
+ }.should raise_error
1534
+ end
1535
+
1536
+ it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1537
+ @worksheet.is_column_bolded(11).should be_nil
1538
+ end
1539
+ end
1540
+
1541
+ describe '.is_column_underlined' do
1542
+ it 'should correctly return whether column is underlined' do
1543
+ @worksheet.change_column_underline(0,true)
1544
+ @worksheet.is_column_underlined(0).should == true
1545
+ end
1546
+
1547
+ it 'should cause error if a negative argument is passed in' do
1548
+ lambda {
1549
+ @worksheet.is_column_underlined(-1)
1550
+ }.should raise_error
1551
+ end
1552
+
1553
+ it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1554
+ @worksheet.is_column_underlined(11).should be_nil
1555
+ end
1556
+ end
1557
+
1558
+ describe '.is_column_struckthrough' do
1559
+ it 'should correctly return whether column is struckthrough' do
1560
+ @worksheet.change_column_strikethrough(0,true)
1561
+ @worksheet.is_column_struckthrough(0).should == true
1562
+ end
1563
+
1564
+ it 'should cause error if a negative argument is passed in' do
1565
+ lambda {
1566
+ @worksheet.is_column_struckthrough(-1)
1567
+ }.should raise_error
1568
+ end
1569
+
1570
+ it 'should return nil if a (nonnegative) column which does not exist is passed in' do
1571
+ @worksheet.is_column_struckthrough(11).should be_nil
1572
+ end
1573
+ end
1574
+
1575
+ describe '.get_column_width' do
1576
+ it 'should return 10 (base column width) if no width specified for column' do
1577
+ @worksheet.get_column_width(0).should == 10
1578
+ end
1579
+
1580
+ it 'should correctly reflect width if specified for column' do
1581
+ @worksheet.change_column_width(0, 30)
1582
+ @worksheet.get_column_width(0).should == 30
1583
+ end
1584
+
1585
+ it 'should return nil if a column which does not exist is passed in' do
1586
+ @worksheet.get_column_width(11).should be_nil
1587
+ end
1588
+
1589
+ it 'should cause error if a negative argument is passed in' do
1590
+ lambda {
1591
+ @worksheet.get_column_width(-1)
1592
+ }.should raise_error
1593
+ end
1594
+ end
1595
+
1596
+ describe '.get_column_fill' do
1597
+ it 'should return white (ffffff) if no fill color specified for column' do
1598
+ @worksheet.get_column_fill(0).should == 'ffffff'
1599
+ end
1600
+
1601
+ it 'should correctly reflect fill color if specified for column' do
1602
+ @worksheet.change_column_fill(0, '000000')
1603
+ @worksheet.get_column_fill(0).should == '000000'
1604
+ end
1605
+
1606
+ it 'should return nil if a column which does not exist is passed in' do
1607
+ @worksheet.get_column_fill(11).should be_nil
1608
+ end
1609
+
1610
+ it 'should cause error if a negative argument is passed in' do
1611
+ lambda {
1612
+ @worksheet.get_column_fill(-1)
1613
+ }.should raise_error
1614
+ end
1615
+ end
1616
+
1617
+ describe '.get_column_horizontal_alignment' do
1618
+ it 'should return nil if no alignment specified for column' do
1619
+ @worksheet.get_column_horizontal_alignment(0).should be_nil
1620
+ end
1621
+
1622
+ it 'should return nil if a column which does not exist is passed in' do
1623
+ @worksheet.get_column_horizontal_alignment(11).should be_nil
1624
+ end
1625
+
1626
+ it 'should cause error if a negative argument is passed in' do
1627
+ lambda {
1628
+ @worksheet.get_column_horizontal_alignment(-1)
1629
+ }.should raise_error
1630
+ end
1631
+
1632
+ it 'should return correct horizontal alignment if it is set for that column' do
1633
+ @worksheet.change_column_horizontal_alignment(0, 'center')
1634
+ @worksheet.get_column_horizontal_alignment(0).should == 'center'
1635
+ end
1636
+ end
1637
+
1638
+ describe '.get_column_vertical_alignment' do
1639
+ it 'should return nil if no alignment specified for column' do
1640
+ @worksheet.get_column_vertical_alignment(0).should be_nil
1641
+ end
1642
+
1643
+ it 'should return nil if a column which does not exist is passed in' do
1644
+ @worksheet.get_column_vertical_alignment(11).should be_nil
1645
+ end
1646
+
1647
+ it 'should cause error if a negative argument is passed in' do
1648
+ lambda {
1649
+ @worksheet.get_column_vertical_alignment(-1)
1650
+ }.should raise_error
1651
+ end
1652
+
1653
+ it 'should return correct vertical alignment if it is set for that column' do
1654
+ @worksheet.change_column_vertical_alignment(0, 'center')
1655
+ @worksheet.get_column_vertical_alignment(0).should == 'center'
1656
+ end
1657
+ end
1658
+
1659
+ describe '.get_column_border_top' do
1660
+ it 'should return nil if no border is specified for that column in that direction' do
1661
+ @worksheet.get_column_border_top(0).should be_nil
1662
+ end
1663
+
1664
+ it 'should return type of border that this column has on top' do
1665
+ @worksheet.change_column_border_top(0,'thin')
1666
+ @worksheet.get_column_border_top(0).should == 'thin'
1667
+ end
1668
+
1669
+ it 'should cause error if a negative argument is passed in' do
1670
+ lambda {
1671
+ @worksheet.get_column_border_top(-1)
1672
+ }.should raise_error
1673
+ end
1674
+
1675
+ it 'should return nil if a column which does not exist is passed in' do
1676
+ @worksheet.get_column_border_top(11).should be_nil
1677
+ end
1678
+ end
1679
+
1680
+ describe '.get_column_border_left' do
1681
+ it 'should return nil if no border is specified for that column in that direction' do
1682
+ @worksheet.get_column_border_left(0).should be_nil
1683
+ end
1684
+
1685
+ it 'should return type of border that this column has on left' do
1686
+ @worksheet.change_column_border_left(0,'thin')
1687
+ @worksheet.get_column_border_left(0).should == 'thin'
1688
+ end
1689
+
1690
+ it 'should cause error if a negative argument is passed in' do
1691
+ lambda {
1692
+ @worksheet.get_column_border_left(-1)
1693
+ }.should raise_error
1694
+ end
1695
+
1696
+ it 'should return nil if a column which does not exist is passed in' do
1697
+ @worksheet.get_column_border_left(11).should be_nil
1698
+ end
1699
+ end
1700
+
1701
+ describe '.get_column_border_right' do
1702
+ it 'should return nil if no border is specified for that column in that direction' do
1703
+ @worksheet.get_column_border_right(0).should be_nil
1704
+ end
1705
+
1706
+ it 'should return type of border that this column has on right' do
1707
+ @worksheet.change_column_border_right(0,'thin')
1708
+ @worksheet.get_column_border_right(0).should == 'thin'
1709
+ end
1710
+
1711
+ it 'should cause error if a negative argument is passed in' do
1712
+ lambda {
1713
+ @worksheet.get_column_border_right(-1)
1714
+ }.should raise_error
1715
+ end
1716
+
1717
+ it 'should return nil if a column which does not exist is passed in' do
1718
+ @worksheet.get_column_border_right(11).should be_nil
1719
+ end
1720
+ end
1721
+
1722
+ describe '.get_column_border_bottom' do
1723
+ it 'should return nil if no border is specified for that column in that direction' do
1724
+ @worksheet.get_column_border_bottom(0).should be_nil
1725
+ end
1726
+
1727
+ it 'should return type of border that this column has on bottom' do
1728
+ @worksheet.change_column_border_bottom(0,'thin')
1729
+ @worksheet.get_column_border_bottom(0).should == 'thin'
1730
+ end
1731
+
1732
+ it 'should cause error if a negative argument is passed in' do
1733
+ lambda {
1734
+ @worksheet.get_column_border_bottom(-1)
1735
+ }.should raise_error
1736
+ end
1737
+
1738
+ it 'should return nil if a column which does not exist is passed in' do
1739
+ @worksheet.get_column_border_bottom(11).should be_nil
1740
+ end
1741
+ end
1742
+
1743
+ describe '.get_column_border_diagonal' do
1744
+ it 'should return nil if no border is specified for that column in that direction' do
1745
+ @worksheet.get_column_border_diagonal(0).should be_nil
1746
+ end
1747
+
1748
+ it 'should return type of border that this column has on diagonal' do
1749
+ @worksheet.change_column_border_diagonal(0,'thin')
1750
+ @worksheet.get_column_border_diagonal(0).should == 'thin'
1751
+ end
1752
+
1753
+ it 'should cause error if a negative argument is passed in' do
1754
+ lambda {
1755
+ @worksheet.get_column_border_diagonal(-1)
1756
+ }.should raise_error
1757
+ end
1758
+
1759
+ it 'should return nil if a column which does not exist is passed in' do
1760
+ @worksheet.get_column_border_diagonal(11).should be_nil
1761
+ end
1762
+ end
1763
+
1764
+
1765
+ describe '@column_range' do
1766
+ it 'should properly handle range addition and modification' do
1767
+ # Ranges should be empty for brand new worskeet
1768
+ @worksheet.column_ranges.size.should == 0
1769
+
1770
+ # Range should be created if the column has not been touched before
1771
+ @worksheet.change_column_width(0, 30)
1772
+ @worksheet.get_column_width(0).should == 30
1773
+ @worksheet.column_ranges.size.should == 1
1774
+
1775
+ # Range should be reused if the column has not been touched before
1776
+ @worksheet.change_column_width(0, 20)
1777
+ @worksheet.get_column_width(0).should == 20
1778
+ @worksheet.column_ranges.size.should == 1
1779
+
1780
+ # Creation of the new range should not affect previously changed columns
1781
+ @worksheet.change_column_width(1, 999)
1782
+ @worksheet.get_column_width(1).should == 999
1783
+ @worksheet.get_column_width(0).should == 20
1784
+ @worksheet.column_ranges.size.should == 2
1785
+ end
1786
+
1787
+ end
1788
+
1789
+ end