listen360-rubyXL 1.2.10.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,230 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+
4
+ module RubyXL
5
+ module Writer
6
+ class WorksheetWriter
7
+ attr_accessor :dirpath, :filepath, :sheet_num, :workbook, :worksheet
8
+
9
+ def initialize(dirpath, wb, sheet_num=1)
10
+ @dirpath = dirpath
11
+ @workbook = wb
12
+ @sheet_num = sheet_num
13
+ @worksheet = @workbook.worksheets[@sheet_num]
14
+ @filepath = dirpath + '/xl/worksheets/sheet'+(sheet_num+1).to_s()+'.xml'
15
+ end
16
+
17
+ def write()
18
+ builder = Nokogiri::XML::Builder.new do |xml|
19
+ xml.worksheet('xmlns'=>"http://schemas.openxmlformats.org/spreadsheetml/2006/main",
20
+ 'xmlns:r'=>"http://schemas.openxmlformats.org/officeDocument/2006/relationships",
21
+ 'xmlns:mc'=>"http://schemas.openxmlformats.org/markup-compatibility/2006",
22
+ 'xmlns:mv'=>"urn:schemas-microsoft-com:mac:vml",
23
+ 'mc:Ignorable'=>'mv',
24
+ 'mc:PreserveAttributes'=>'mv:*') {
25
+ col = 0
26
+ @worksheet.sheet_data.each do |row|
27
+ if row.size > col
28
+ col = row.size
29
+ end
30
+ end
31
+ row = Integer(@worksheet.sheet_data.size)
32
+ dimension = 'A1:'
33
+ dimension += Cell.convert_to_cell(row-1,col-1)
34
+ xml.dimension('ref'=>dimension)
35
+ xml.sheetViews {
36
+ view = @worksheet.sheet_view
37
+ if view.nil? || view[:attributes].nil?
38
+ xml.sheetView('tabSelected'=>1,'view'=>'normalLayout','workbookViewId'=>0)
39
+ raise 'end test' #TODO remove
40
+ else
41
+ view = view[:attributes]
42
+ if view[:view].nil?
43
+ view[:view] = 'normalLayout'
44
+ end
45
+
46
+ if view[:workbookViewId].nil?
47
+ view[:workbookViewId] = 0
48
+ end
49
+
50
+ if view[:zoomScale].nil? || view[:zoomScaleNormal].nil?
51
+ view[:zoomScale] = 100
52
+ view[:zoomScaleNormal] = 100
53
+ end
54
+
55
+ if view[:tabSelected].nil?
56
+ view[:tabSelected] = 1
57
+ end
58
+
59
+ xml.sheetView('tabSelected'=>view[:tabSelected],
60
+ 'view'=>view[:view],
61
+ 'workbookViewId'=>view[:workbookViewId],
62
+ 'zoomScale'=>view[:zoomScale],
63
+ 'zoomScaleNormal'=>view[:zoomScaleNormal]) {
64
+ #TODO
65
+ #can't be done unless I figure out a way to programmatically add attributes.
66
+ #(can't put xSplit with an invalid value)
67
+ # unless @worksheet.pane.nil?
68
+ # xml.pane('state'=>@worksheet.pane[:state])
69
+ # end
70
+ # unless view[:selection].nil?
71
+ # xml.
72
+ # end
73
+ }
74
+ end
75
+ }
76
+ xml.sheetFormatPr('baseColWidth'=>'10','defaultRowHeight'=>'13')
77
+
78
+ unless @worksheet.cols.nil? || @worksheet.cols.size==0
79
+ xml.cols {
80
+ if !@worksheet.cols.is_a?(Array)
81
+ @worksheet.cols = [@worksheet.cols]
82
+ end
83
+ @worksheet.cols.each do |col|
84
+ if col[:attributes][:customWidth].nil?
85
+ col[:attributes][:customWidth] = '0'
86
+ end
87
+ if col[:attributes][:width].nil?
88
+ col[:attributes][:width] = '10'
89
+ col[:attributes][:customWidth] = '0'
90
+ end
91
+ # unless col[:attributes] == {}
92
+ xml.col('style'=>@workbook.style_corrector[col[:attributes][:style].to_s].to_s,
93
+ 'min'=>col[:attributes][:min].to_s,
94
+ 'max'=>col[:attributes][:max].to_s,
95
+ 'width'=>col[:attributes][:width].to_s,
96
+ 'customWidth'=>col[:attributes][:customWidth].to_s)
97
+ # end
98
+ end
99
+ }
100
+ end
101
+
102
+ xml.sheetData {
103
+ i=0
104
+ @worksheet.sheet_data.each_with_index do |row,i|
105
+ #TODO fix this spans thing. could be 2:3 (not necessary)
106
+ if @worksheet.row_styles[(i+1).to_s].nil?
107
+ @worksheet.row_styles[(i+1).to_s] = {}
108
+ @worksheet.row_styles[(i+1).to_s][:style] = '0'
109
+ end
110
+ custom_format = '1'
111
+ if @worksheet.row_styles[(i+1).to_s][:style] == '0'
112
+ custom_format = '0'
113
+ end
114
+
115
+ @worksheet.row_styles[(i+1).to_s][:style] = @workbook.style_corrector[@worksheet.row_styles[(i+1).to_s][:style].to_s]
116
+ row_opts = {
117
+ 'r'=>(i+1).to_s,
118
+ 'spans'=>'1:'+row.size.to_s,
119
+ 'customFormat'=>custom_format
120
+ }
121
+ unless @worksheet.row_styles[(i+1).to_s][:style].to_s == ''
122
+ row_opts['s'] = @worksheet.row_styles[(i+1).to_s][:style].to_s
123
+ end
124
+ unless @worksheet.row_styles[(i+1).to_s][:height].to_s == ''
125
+ row_opts['ht'] = @worksheet.row_styles[(i+1).to_s][:height].to_s
126
+ end
127
+ unless @worksheet.row_styles[(i+1).to_s][:customheight].to_s == ''
128
+ row_opts['customHeight'] = @worksheet.row_styles[(i+1).to_s][:customHeight].to_s
129
+ end
130
+ xml.row(row_opts) {
131
+ row.each_with_index do |dat, j|
132
+ unless dat.nil?
133
+ #TODO do xml.c for all cases, inside specific.
134
+ # if dat.formula.nil?
135
+ dat.style_index = @workbook.style_corrector[dat.style_index.to_s]
136
+ c_opts = {'r'=>Cell.convert_to_cell(i,j), 's'=>dat.style_index.to_s}
137
+ unless dat.datatype.nil? || dat.datatype == ''
138
+ c_opts['t'] = dat.datatype
139
+ end
140
+ xml.c(c_opts) {
141
+ unless dat.formula.nil?
142
+ if dat.formula_attributes.nil? || dat.formula_attributes.empty?
143
+ xml.f dat.formula.to_s
144
+ else
145
+ xml.f('t'=>dat.formula_attributes['t'].to_s, 'ref'=>dat.formula_attributes['ref'], 'si'=>dat.formula_attributes['si']).nokogiri dat.formula
146
+ end
147
+ end
148
+ if(dat.datatype == 's')
149
+ unless dat.value.nil? #empty cell, but has a style
150
+ xml.v @workbook.shared_strings[dat.value].to_s
151
+ end
152
+ elsif(dat.datatype == 'str')
153
+ xml.v dat.value.to_s
154
+ elsif(dat.datatype == '') #number
155
+ xml.v dat.value.to_s
156
+ end
157
+ }
158
+ #
159
+ # else
160
+ # xml.c('r'=>Cell.convert_to_cell(i,j)) {
161
+ # xml.v dat.value.to_s
162
+ # }
163
+ # end #data.formula.nil?
164
+ end #unless dat.nil?
165
+ end #row.each_with_index
166
+ }
167
+ end
168
+ }
169
+
170
+
171
+ xml.sheetCalcPr('fullCalcOnLoad'=>'1')
172
+
173
+ unless @worksheet.merged_cells.nil? || @worksheet.merged_cells.size==0
174
+ #There is some kind of bug here that when merged_cells is sometimes a hash and not an array
175
+ #initial attempt at a fix fails in corrupted excel documents leaving as is for now.
176
+ xml.mergeCells {
177
+ @worksheet.merged_cells.each do |merged_cell|
178
+ xml.mergeCell('ref'=>merged_cell[:attributes][:ref].to_s)
179
+ end
180
+ }
181
+ end
182
+
183
+ xml.phoneticPr('fontId'=>'1','type'=>'noConversion')
184
+
185
+ unless @worksheet.validations.nil?
186
+ xml.dataValidations('count'=>@worksheet.validations.size.to_s) {
187
+ @worksheet.validations.each do |validation|
188
+ xml.dataValidation('type'=>validation[:attributes][:type],
189
+ 'sqref'=>validation[:attributes][:sqref],
190
+ 'allowBlank'=>Integer(validation[:attributes][:allowBlank]).to_s,
191
+ 'showInputMessage'=>Integer(validation[:attributes][:showInputMessage]).to_s,
192
+ 'showErrorMessage'=>Integer(validation[:attributes][:showErrorMessage]).to_s) {
193
+ unless validation[:formula1].nil?
194
+ xml.formula1 validation[:formula1]
195
+ end
196
+ }
197
+ end
198
+ }
199
+ end
200
+
201
+ xml.pageMargins('left'=>'0.75','right'=>'0.75','top'=>'1',
202
+ 'bottom'=>'1','header'=>'0.5','footer'=>'0.5')
203
+
204
+ xml.pageSetup('orientation'=>'portrait',
205
+ 'horizontalDpi'=>'4294967292', 'verticalDpi'=>'4294967292')
206
+
207
+ unless @worksheet.legacy_drawing.nil?
208
+ xml.legacyDrawing('r:id'=>@worksheet.legacy_drawing[:attributes][:id])
209
+ end
210
+
211
+ unless @worksheet.extLst.nil?
212
+ xml.extLst {
213
+ xml.ext('xmlns:mx'=>"http://schemas.microsoft.com/office/mac/excel/2008/main",
214
+ 'uri'=>"http://schemas.microsoft.com/office/mac/excel/2008/main") {
215
+ xml['mx'].PLV('Mode'=>'1', 'OnePage'=>'0','WScale'=>'0')
216
+ }
217
+ }
218
+ end
219
+ }
220
+ end
221
+ contents = builder.to_xml
222
+ contents = contents.gsub(/\n/,'')
223
+ contents = contents.gsub(/>(\s)+</,'><')
224
+ contents = contents.sub(/<\?xml version=\"1.0\"\?>/,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\n")
225
+ contents
226
+ end
227
+
228
+ end
229
+ end
230
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'zip/zip'
3
+ require 'zip/zipfilesystem'
4
+
5
+ module RubyXL
6
+ class MyZip
7
+
8
+ # Unzips .zip file at zipPath to zipDirPath
9
+ def unzip(zipPath,zipDirPath)
10
+ Zip::ZipFile.open(zipPath) { |zip_file|
11
+ zip_file.each { |f|
12
+ fpath = File.join(zipDirPath, f.name)
13
+ FileUtils.mkdir_p(File.dirname(fpath))
14
+ zip_file.extract(f, fpath) unless File.exist?(fpath)
15
+ }
16
+ }
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,92 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{listen360-rubyXL}
8
+ s.version = "1.2.10.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Vivek Bhagwat"]
12
+ s.date = %q{2013-11-27}
13
+ s.description = %q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents}
14
+ s.email = %q{bhagwat.vivek@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/.DS_Store",
27
+ "lib/rubyXL.rb",
28
+ "lib/rubyXL/Hash.rb",
29
+ "lib/rubyXL/cell.rb",
30
+ "lib/rubyXL/color.rb",
31
+ "lib/rubyXL/parser.rb",
32
+ "lib/rubyXL/private_class.rb",
33
+ "lib/rubyXL/workbook.rb",
34
+ "lib/rubyXL/worksheet.rb",
35
+ "lib/rubyXL/writer/app_writer.rb",
36
+ "lib/rubyXL/writer/calc_chain_writer.rb",
37
+ "lib/rubyXL/writer/content_types_writer.rb",
38
+ "lib/rubyXL/writer/core_writer.rb",
39
+ "lib/rubyXL/writer/root_rels_writer.rb",
40
+ "lib/rubyXL/writer/shared_strings_writer.rb",
41
+ "lib/rubyXL/writer/styles_writer.rb",
42
+ "lib/rubyXL/writer/theme_writer.rb",
43
+ "lib/rubyXL/writer/workbook_rels_writer.rb",
44
+ "lib/rubyXL/writer/workbook_writer.rb",
45
+ "lib/rubyXL/writer/worksheet_writer.rb",
46
+ "lib/rubyXL/zip.rb",
47
+ "rubyXL.gemspec",
48
+ "spec/lib/cell_spec.rb",
49
+ "spec/lib/color_spec.rb",
50
+ "spec/lib/hash_spec.rb",
51
+ "spec/lib/parser_spec.rb",
52
+ "spec/lib/workbook_spec.rb",
53
+ "spec/lib/worksheet_spec.rb"
54
+ ]
55
+ s.homepage = %q{http://github.com/gilt/rubyXL}
56
+ s.licenses = ["MIT"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.3.7}
59
+ s.summary = %q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx/.xlsm) Documents}
60
+
61
+ if s.respond_to? :specification_version then
62
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
+ s.specification_version = 3
64
+
65
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
67
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
69
+ s.add_development_dependency(%q<rcov>, [">= 0"])
70
+ s.add_development_dependency(%q<nokogiri>, [">= 1.4.4"])
71
+ s.add_development_dependency(%q<rubyzip>, [">= 0.9.4"])
72
+ s.add_development_dependency(%q<rspec>, [">= 1.3.4"])
73
+ else
74
+ s.add_dependency(%q<shoulda>, [">= 0"])
75
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
77
+ s.add_dependency(%q<rcov>, [">= 0"])
78
+ s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
79
+ s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
80
+ s.add_dependency(%q<rspec>, [">= 1.3.4"])
81
+ end
82
+ else
83
+ s.add_dependency(%q<shoulda>, [">= 0"])
84
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
85
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
86
+ s.add_dependency(%q<rcov>, [">= 0"])
87
+ s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
88
+ s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
89
+ s.add_dependency(%q<rspec>, [">= 1.3.4"])
90
+ end
91
+ end
92
+
@@ -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