thunderboltlabs-rubyXL 1.2.10.1
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.
- checksums.yaml +15 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +197 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/.DS_Store +0 -0
- data/lib/rubyXL/Hash.rb +60 -0
- data/lib/rubyXL/cell.rb +461 -0
- data/lib/rubyXL/color.rb +14 -0
- data/lib/rubyXL/parser.rb +471 -0
- data/lib/rubyXL/private_class.rb +265 -0
- data/lib/rubyXL/workbook.rb +450 -0
- data/lib/rubyXL/worksheet.rb +1493 -0
- data/lib/rubyXL/writer/app_writer.rb +62 -0
- data/lib/rubyXL/writer/calc_chain_writer.rb +33 -0
- data/lib/rubyXL/writer/content_types_writer.rb +77 -0
- data/lib/rubyXL/writer/core_writer.rb +51 -0
- data/lib/rubyXL/writer/root_rels_writer.rb +25 -0
- data/lib/rubyXL/writer/shared_strings_writer.rb +30 -0
- data/lib/rubyXL/writer/styles_writer.rb +407 -0
- data/lib/rubyXL/writer/theme_writer.rb +343 -0
- data/lib/rubyXL/writer/workbook_rels_writer.rb +59 -0
- data/lib/rubyXL/writer/workbook_writer.rb +77 -0
- data/lib/rubyXL/writer/worksheet_writer.rb +230 -0
- data/lib/rubyXL/zip.rb +20 -0
- data/lib/rubyXL.rb +10 -0
- data/rubyXL.gemspec +92 -0
- data/spec/lib/cell_spec.rb +385 -0
- data/spec/lib/color_spec.rb +14 -0
- data/spec/lib/hash_spec.rb +28 -0
- data/spec/lib/parser_spec.rb +66 -0
- data/spec/lib/workbook_spec.rb +51 -0
- data/spec/lib/worksheet_spec.rb +1782 -0
- metadata +179 -0
@@ -0,0 +1,385 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubyXL'
|
3
|
+
|
4
|
+
describe RubyXL::Cell do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@workbook = RubyXL::Workbook.new
|
8
|
+
@worksheet = RubyXL::Worksheet.new(@workbook)
|
9
|
+
@workbook.worksheets << @worksheet
|
10
|
+
(0..10).each do |i|
|
11
|
+
(0..10).each do |j|
|
12
|
+
@worksheet.add_cell(i, j, "#{i}:#{j}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
@cell = @worksheet[0][0]
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.change_fill' do
|
19
|
+
it 'should cause an error if hex color code not passed' do
|
20
|
+
lambda {
|
21
|
+
@cell.change_fill('G')
|
22
|
+
}.should raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should make cell fill color equal to hex color code passed' do
|
26
|
+
@cell.change_fill('0f0f0f')
|
27
|
+
@cell.fill_color.should == '0f0f0f'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should cause an error if hex color code includes # character' do
|
31
|
+
lambda {
|
32
|
+
@cell.change_fill('#0f0f0f')
|
33
|
+
}.should raise_error
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.change_font_name' do
|
38
|
+
it 'should make font name match font name passed' do
|
39
|
+
@cell.change_font_name('Arial')
|
40
|
+
@cell.font_name.should == 'Arial'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '.change_font_size' do
|
45
|
+
it 'should make font size match number passed' do
|
46
|
+
@cell.change_font_size(30)
|
47
|
+
@cell.font_size.should == 30
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should cause an error if a string passed' do
|
51
|
+
lambda {
|
52
|
+
@cell.change_font_size('20')
|
53
|
+
}.should raise_error
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '.change_font_color' do
|
58
|
+
it 'should cause an error if hex color code not passed' do
|
59
|
+
lambda {
|
60
|
+
@cell.change_font_color('G')
|
61
|
+
}.should raise_error
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should make cell font color equal to hex color code passed' do
|
65
|
+
@cell.change_font_color('0f0f0f')
|
66
|
+
@cell.font_color.should == '0f0f0f'
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should cause an error if hex color code includes # character' do
|
70
|
+
lambda {
|
71
|
+
@cell.change_font_color('#0f0f0f')
|
72
|
+
}.should raise_error
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.change_font_italics' do
|
77
|
+
it 'should make cell font italicized when true is passed' do
|
78
|
+
@cell.change_font_italics(true)
|
79
|
+
@cell.is_italicized.should == true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '.change_font_bold' do
|
84
|
+
it 'should make cell font bolded when true is passed' do
|
85
|
+
@cell.change_font_bold(true)
|
86
|
+
@cell.is_bolded.should == true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '.change_font_underline' do
|
91
|
+
it 'should make cell font underlined when true is passed' do
|
92
|
+
@cell.change_font_underline(true)
|
93
|
+
@cell.is_underlined.should == true
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '.change_font_strikethrough' do
|
98
|
+
it 'should make cell font struckthrough when true is passed' do
|
99
|
+
@cell.change_font_strikethrough(true)
|
100
|
+
@cell.is_struckthrough.should == true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '.change_horizontal_alignment' do
|
105
|
+
it 'should cause cell to horizontally align as specified by the passed in string' do
|
106
|
+
@cell.change_horizontal_alignment('center')
|
107
|
+
@cell.horizontal_alignment.should == 'center'
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should cause error if nil, "center", "justify", "left", "right", or "distributed" is not passed' do
|
111
|
+
lambda {
|
112
|
+
@cell.change_horizontal_alignment('TEST')
|
113
|
+
}.should raise_error
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.change_vertical_alignment' do
|
118
|
+
it 'should cause cell to vertically align as specified by the passed in string' do
|
119
|
+
@cell.change_vertical_alignment('center')
|
120
|
+
@cell.vertical_alignment.should == 'center'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should cause error if nil, "center", "justify", "left", "right", or "distributed" is not passed' do
|
124
|
+
lambda {
|
125
|
+
@cell.change_vertical_alignment('TEST')
|
126
|
+
}.should raise_error
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '.change_border_top' do
|
131
|
+
it 'should cause cell to have border at top with specified weight' do
|
132
|
+
@cell.change_border_top('thin')
|
133
|
+
@cell.border_top.should == 'thin'
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
|
137
|
+
lambda {
|
138
|
+
@cell.change_border_top('TEST')
|
139
|
+
}.should raise_error
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '.change_border_left' do
|
144
|
+
it 'should cause cell to have border at left with specified weight' do
|
145
|
+
@cell.change_border_left('thin')
|
146
|
+
@cell.border_left.should == 'thin'
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
|
150
|
+
lambda {
|
151
|
+
@cell.change_border_left('TEST')
|
152
|
+
}.should raise_error
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '.change_border_right' do
|
157
|
+
it 'should cause cell to have border at right with specified weight' do
|
158
|
+
@cell.change_border_right('thin')
|
159
|
+
@cell.border_right.should == 'thin'
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
|
163
|
+
lambda {
|
164
|
+
@cell.change_border_right('TEST')
|
165
|
+
}.should raise_error
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '.change_border_bottom' do
|
170
|
+
it 'should cause cell to have border at bottom with specified weight' do
|
171
|
+
@cell.change_border_bottom('thin')
|
172
|
+
@cell.border_bottom.should == 'thin'
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
|
176
|
+
lambda {
|
177
|
+
@cell.change_border_bottom('TEST')
|
178
|
+
}.should raise_error
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe '.change_border_diagonal' do
|
183
|
+
it 'should cause cell to have border at diagonal with specified weight' do
|
184
|
+
@cell.change_border_diagonal('thin')
|
185
|
+
@cell.border_diagonal.should == 'thin'
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should cause error if nil, "thin", "thick", "hairline", or "medium" is not passed' do
|
189
|
+
lambda {
|
190
|
+
@cell.change_border_diagonal('TEST')
|
191
|
+
}.should raise_error
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '.value' do
|
196
|
+
it 'should return the value of a date' do
|
197
|
+
date = Date.parse('January 1, 2011')
|
198
|
+
@cell.change_contents(date)
|
199
|
+
@cell.should_receive(:is_date?).any_number_of_times.and_return(true)
|
200
|
+
@cell.value.should == date
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should convert date numbers correctly' do
|
204
|
+
date = 41019
|
205
|
+
@cell.change_contents(date)
|
206
|
+
@cell.should_receive(:is_date?).any_number_of_times.and_return(true)
|
207
|
+
puts @cell.value
|
208
|
+
puts Date.parse('April 20, 2012')
|
209
|
+
@cell.value.should == Date.parse('April 20, 2012')
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '.change_contents' do
|
214
|
+
it 'should cause cell value to match string or number that is passed in' do
|
215
|
+
@cell.change_contents('TEST')
|
216
|
+
@cell.value.should == 'TEST'
|
217
|
+
@cell.formula.should == nil
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should cause cell value to match a date that is passed in' do
|
221
|
+
date = Date.parse('January 1, 2011')
|
222
|
+
@cell.change_contents(date)
|
223
|
+
@cell.should_receive(:is_date?).any_number_of_times.and_return(true)
|
224
|
+
@cell.value.should == date
|
225
|
+
@cell.formula.should == nil
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should cause cell value and formula to match what is passed in' do
|
229
|
+
@cell.change_contents(nil, 'SUM(A2:A4)')
|
230
|
+
@cell.value.should == nil
|
231
|
+
@cell.formula.should == 'SUM(A2:A4)'
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe '.is_italicized' do
|
236
|
+
it 'should correctly return whether or not the cell\'s font is italicized' do
|
237
|
+
@cell.change_font_italics(true)
|
238
|
+
@cell.is_italicized.should == true
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
describe '.is_bolded' do
|
243
|
+
it 'should correctly return whether or not the cell\'s font is bolded' do
|
244
|
+
@cell.change_font_bold(true)
|
245
|
+
@cell.is_bolded.should == true
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe '.is_underlined' do
|
250
|
+
it 'should correctly return whether or not the cell\'s font is underlined' do
|
251
|
+
@cell.change_font_underline(true)
|
252
|
+
@cell.is_underlined.should == true
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe '.is_struckthrough' do
|
257
|
+
it 'should correctly return whether or not the cell\'s font is struckthrough' do
|
258
|
+
@cell.change_font_strikethrough(true)
|
259
|
+
@cell.is_struckthrough.should == true
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '.font_name' do
|
264
|
+
it 'should correctly return the name of the cell\'s font' do
|
265
|
+
@cell.change_font_name('Verdana')
|
266
|
+
@cell.font_name.should == 'Verdana'
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
describe '.font_size' do
|
271
|
+
it 'should correctly return the size of the cell\'s font' do
|
272
|
+
@cell.change_font_size(20)
|
273
|
+
@cell.font_size.should == 20
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
describe '.font_color' do
|
278
|
+
it 'should correctly return the color of the cell\'s font' do
|
279
|
+
@cell.change_font_color('0f0f0f')
|
280
|
+
@cell.font_color.should == '0f0f0f'
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'should return 000000 (black) if no font color has been specified for this cell' do
|
284
|
+
@cell.font_color.should == '000000'
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe '.fill_color' do
|
289
|
+
it 'should correctly return the color of the cell\'s fill' do
|
290
|
+
@cell.change_fill('000000')
|
291
|
+
@cell.fill_color.should == '000000'
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'should return ffffff (white) if no fill color has been specified for this cell' do
|
295
|
+
@cell.fill_color.should == 'ffffff'
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
describe '.horizontal_alignment' do
|
300
|
+
it 'should correctly return the type of horizontal alignment of this cell' do
|
301
|
+
@cell.change_horizontal_alignment('center')
|
302
|
+
@cell.horizontal_alignment.should == 'center'
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'should return nil if no horizontal alignment has been specified for this cell' do
|
306
|
+
@cell.horizontal_alignment.should == nil
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
describe '.vertical_alignment' do
|
311
|
+
it 'should correctly return the type of vertical alignment of this cell' do
|
312
|
+
@cell.change_vertical_alignment('center')
|
313
|
+
@cell.vertical_alignment.should == 'center'
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should return nil if no vertical alignment has been specified for this cell' do
|
317
|
+
@cell.vertical_alignment.should be_nil
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe '.border_top' do
|
322
|
+
it 'should correctly return the weight of the border on top for this cell' do
|
323
|
+
@cell.change_border_top('thin')
|
324
|
+
@cell.border_top.should == 'thin'
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'should return nil if no top border has been specified for this cell' do
|
328
|
+
@cell.border_top.should be_nil
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
describe '.border_left' do
|
333
|
+
it 'should correctly return the weight of the border on left for this cell' do
|
334
|
+
@cell.change_border_left('thin')
|
335
|
+
@cell.border_left.should == 'thin'
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'should return nil if no left border has been specified for this cell' do
|
339
|
+
@cell.border_left.should be_nil
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
describe '.border_right' do
|
344
|
+
it 'should correctly return the weight of the border on right for this cell' do
|
345
|
+
@cell.change_border_right('thin')
|
346
|
+
@cell.border_right.should == 'thin'
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'should return nil if no right border has been specified for this cell' do
|
350
|
+
@cell.border_right.should be_nil
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
describe '.border_bottom' do
|
355
|
+
it 'should correctly return the weight of the border on bottom for this cell' do
|
356
|
+
@cell.change_border_bottom('thin')
|
357
|
+
@cell.border_bottom.should == 'thin'
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'should return nil if no bottom border has been specified for this cell' do
|
361
|
+
@cell.border_bottom.should be_nil
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
describe '.border_diagonal' do
|
366
|
+
it 'should correctly return the weight of the diagonal border for this cell' do
|
367
|
+
@cell.change_border_diagonal('thin')
|
368
|
+
@cell.border_diagonal.should == 'thin'
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'should return nil if no diagonal border has been specified for this cell' do
|
372
|
+
@cell.border_diagonal.should be_nil
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
describe '.convert_to_cell' do
|
377
|
+
it 'should correctly return the "Excel Style" description of cells when given a row/column number' do
|
378
|
+
RubyXL::Cell.convert_to_cell(0,26).should == 'AA1'
|
379
|
+
end
|
380
|
+
|
381
|
+
it 'should cause an error if a negative argument is given' do
|
382
|
+
lambda {RubyXL::Cell.convert_to_cell(-1,0)}.should raise_error
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
@@ -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,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubyXL'
|
3
|
+
|
4
|
+
describe RubyXL::Hash do
|
5
|
+
before do
|
6
|
+
@xml = '<root xmlns:foo="bar"><bar hello="world"/></root>'
|
7
|
+
@hash = {
|
8
|
+
:root => {
|
9
|
+
:bar => { :attributes => { :hello => 'world' } }
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.from_xml' do
|
15
|
+
it 'should create a hash which correctly corresponds to XML' do
|
16
|
+
nokogiri = RubyXL::Hash.from_xml(@xml)
|
17
|
+
nokogiri.should == @hash
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.xml_node_to_hash' do
|
22
|
+
it 'should create a hash which correctly corresponds to a Nokogiri root node' do
|
23
|
+
nokogiri = Nokogiri::XML::Document.parse(@xml)
|
24
|
+
my_hash = RubyXL::Hash.xml_node_to_hash(nokogiri.root)
|
25
|
+
my_hash.should == @hash[:root]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubyXL'
|
3
|
+
|
4
|
+
describe RubyXL::Parser do
|
5
|
+
before do
|
6
|
+
@workbook = (RubyXL::Workbook.new)
|
7
|
+
@time_str = Time.now.to_s
|
8
|
+
@file = @time_str + '.xlsx'
|
9
|
+
@workbook.write(@file)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.convert_to_index' do
|
13
|
+
it 'should convert a well-formed Excel index into a pair of array indices' do
|
14
|
+
RubyXL::Parser.convert_to_index('AA1').should == [0, 26]
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return [-1, -1] if the Excel index is not well-formed' do
|
18
|
+
RubyXL::Parser.convert_to_index('A1B').should == [-1, -1]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.parse' do
|
23
|
+
it 'should parse a valid Excel xlsx or xlsm workbook correctly' do
|
24
|
+
@workbook2 = RubyXL::Parser.parse(@file)
|
25
|
+
|
26
|
+
@workbook2.worksheets.size.should == @workbook.worksheets.size
|
27
|
+
@workbook2[0].sheet_data.should == @workbook[0].sheet_data
|
28
|
+
@workbook2[0].sheet_name.should == @workbook[0].sheet_name
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should cause an error if an xlsx or xlsm workbook is not passed' do
|
32
|
+
lambda {@workbook2 = RubyXL::Parser.parse(@time_str+".xls")}.should raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should not cause an error if an xlsx or xlsm workbook is not passed but the skip_filename_check option is used' do
|
36
|
+
filename = @time_str
|
37
|
+
FileUtils.cp(@file, filename)
|
38
|
+
|
39
|
+
lambda {@workbook2 = RubyXL::Parser.parse(filename)}.should raise_error
|
40
|
+
lambda {@workbook2 = RubyXL::Parser.parse(filename, :skip_filename_check => true)}.should_not raise_error
|
41
|
+
|
42
|
+
File.delete(filename)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should only read the data and not any of the styles (for the sake of speed) when passed true' do
|
46
|
+
@workbook2 = RubyXL::Parser.parse(@file, :data_only => true)
|
47
|
+
|
48
|
+
@workbook2.worksheets.size.should == @workbook.worksheets.size
|
49
|
+
@workbook2[0].sheet_data.should == @workbook[0].sheet_data
|
50
|
+
@workbook2[0].sheet_name.should == @workbook[0].sheet_name
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should construct consistent number formats' do
|
54
|
+
@workbook2 = RubyXL::Parser.parse(@file)
|
55
|
+
|
56
|
+
@workbook2.num_fmts[:numFmt].should be_an(Array)
|
57
|
+
@workbook2.num_fmts[:numFmt].length.should == @workbook2.num_fmts[:attributes][:count]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
after do
|
62
|
+
if File.exist?(@file)
|
63
|
+
File.delete(@file)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubyXL'
|
3
|
+
|
4
|
+
describe RubyXL::Workbook 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
|
+
@cell = @worksheet[0][0]
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.write' do
|
18
|
+
#method not conducive to unit tests
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.get_style' do
|
22
|
+
it 'should return the cell_xfs object based on the passed in style index (string or number)' do
|
23
|
+
@workbook.get_style('0').should == @workbook.cell_xfs[:xf][0]
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return nil if index out of range or string is passed in' do
|
27
|
+
@workbook.get_style('20000').should be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.get_style_attributes' do
|
32
|
+
it 'should return the attributes of the style object when passed the style object itself' do
|
33
|
+
@workbook.get_style_attributes(@workbook.get_style(0)).should == @workbook.cell_xfs[:xf][0][:attributes]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should cause an error if nil is passed' do
|
37
|
+
lambda {@workbook.get_style_attributes(nil)}.should raise_error
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.get_fill_color' do
|
42
|
+
it 'should return the fill color of a particular style attribute' do
|
43
|
+
@cell.change_fill('000000')
|
44
|
+
@workbook.get_fill_color(@workbook.get_style_attributes(@workbook.get_style(@cell.style_index))).should == '000000'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should return white (ffffff) if no fill color is specified in style' do
|
48
|
+
@workbook.get_fill_color(@workbook.get_style_attributes(@workbook.get_style(@cell.style_index))).should == 'ffffff'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|