rubyXL 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +34 -0
  3. data/LICENSE.txt +20 -0
  4. data/README +0 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/lib/.DS_Store +0 -0
  9. data/lib/Hash.rb +60 -0
  10. data/lib/cell.rb +360 -0
  11. data/lib/color.rb +14 -0
  12. data/lib/parser.rb +413 -0
  13. data/lib/private_class.rb +182 -0
  14. data/lib/rubyXL.rb +9 -0
  15. data/lib/test.html +1 -0
  16. data/lib/tests/test.rb +110 -0
  17. data/lib/tests/test10.rb +16 -0
  18. data/lib/tests/test2.rb +118 -0
  19. data/lib/tests/test3.rb +76 -0
  20. data/lib/tests/test4.rb +92 -0
  21. data/lib/tests/test5.rb +90 -0
  22. data/lib/tests/test6.rb +50 -0
  23. data/lib/tests/test7.rb +48 -0
  24. data/lib/tests/test8.rb +12 -0
  25. data/lib/tests/test9.rb +60 -0
  26. data/lib/workbook.rb +336 -0
  27. data/lib/worksheet.rb +1245 -0
  28. data/lib/writer/app_writer.rb +62 -0
  29. data/lib/writer/calc_chain_writer.rb +33 -0
  30. data/lib/writer/content_types_writer.rb +77 -0
  31. data/lib/writer/core_writer.rb +51 -0
  32. data/lib/writer/root_rels_writer.rb +25 -0
  33. data/lib/writer/shared_strings_writer.rb +44 -0
  34. data/lib/writer/styles_writer.rb +376 -0
  35. data/lib/writer/theme_writer.rb +346 -0
  36. data/lib/writer/workbook_rels_writer.rb +59 -0
  37. data/lib/writer/workbook_writer.rb +77 -0
  38. data/lib/writer/worksheet_writer.rb +208 -0
  39. data/lib/zip.rb +20 -0
  40. data/pkg/rubyXL-1.0.4.gem +0 -0
  41. data/rubyXL.gemspec +106 -0
  42. data/spec/lib/cell_spec.rb +359 -0
  43. data/spec/lib/color_spec.rb +14 -0
  44. data/spec/lib/hash_spec.rb +28 -0
  45. data/spec/lib/parser_spec.rb +49 -0
  46. data/spec/lib/workbook_spec.rb +51 -0
  47. data/spec/lib/worksheet_spec.rb +1650 -0
  48. metadata +222 -0
@@ -0,0 +1,208 @@
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
+ @worksheet.cols.each do |col|
81
+ if col[:attributes][:customWidth].nil?
82
+ col[:attributes][:customWidth] = '0'
83
+ end
84
+ if col[:attributes][:width].nil?
85
+ col[:attributes][:width] = '10'
86
+ col[:attributes][:customWidth] = '0'
87
+ end
88
+ # unless col[:attributes] == {}
89
+ xml.col('style'=>@workbook.style_corrector[col[:attributes][:style].to_s].to_s,
90
+ 'min'=>col[:attributes][:min].to_s,
91
+ 'max'=>col[:attributes][:max].to_s,
92
+ 'width'=>col[:attributes][:width].to_s,
93
+ 'customWidth'=>col[:attributes][:customWidth].to_s)
94
+ # end
95
+ end
96
+ }
97
+ end
98
+
99
+ xml.sheetData {
100
+ i=0
101
+ @worksheet.sheet_data.each_with_index do |row,i|
102
+ #TODO fix this spans thing. could be 2:3 (not necessary)
103
+ if @worksheet.row_styles[(i+1).to_s].nil?
104
+ @worksheet.row_styles[(i+1).to_s] = {}
105
+ @worksheet.row_styles[(i+1).to_s][:style] = '0'
106
+ end
107
+ custom_format = '1'
108
+ if @worksheet.row_styles[(i+1).to_s][:style] == '0'
109
+ custom_format = '0'
110
+ end
111
+
112
+ xml.row('r'=>(i+1).to_s, 'spans'=>'1:'+row.size.to_s,
113
+ 's'=>@workbook.style_corrector[@worksheet.row_styles[(i+1).to_s][:style].to_s].to_s,
114
+ 'customFormat'=>custom_format,
115
+ 'ht'=>@worksheet.row_styles[(i+1).to_s][:height].to_s,
116
+ 'customHeight'=>@worksheet.row_styles[(i+1).to_s][:customHeight].to_s) {
117
+ row.each_with_index do |dat, j|
118
+ unless dat.nil?
119
+ #TODO un-hardcode t value, needs to be other values too
120
+ #TODO recalculate based on formula....?
121
+ #TODO do xml.c for all cases, inside specific.
122
+ # if dat.formula.nil?
123
+ xml.c('r'=>Cell.convert_to_cell(i,j),
124
+ 's'=>@workbook.style_corrector[dat.style_index.to_s].to_s, 't'=>dat.datatype) {
125
+ unless dat.formula.nil?
126
+ xml.f dat.formula.to_s
127
+ end
128
+ if(dat.datatype == 's')
129
+ unless dat.value.nil? #empty cell, but has a style
130
+ xml.v @workbook.shared_strings[dat.value].to_s
131
+ end
132
+ elsif(dat.datatype == 'str')
133
+ xml.v dat.value.to_s
134
+ elsif(dat.datatype == '') #number
135
+ xml.v dat.value.to_s
136
+ end
137
+ }
138
+ #
139
+ # else
140
+ # xml.c('r'=>Cell.convert_to_cell(i,j)) {
141
+ # xml.v dat.value.to_s
142
+ # }
143
+ # end #data.formula.nil?
144
+ end #unless dat.nil?
145
+ end #row.each_with_index
146
+ }
147
+ end
148
+ }
149
+
150
+
151
+ xml.sheetCalcPr('fullCalcOnLoad'=>'1')
152
+
153
+ unless @worksheet.merged_cells.nil? || @worksheet.merged_cells.size==0
154
+ xml.mergeCells {
155
+ @worksheet.merged_cells.each do |merged_cell|
156
+ xml.mergeCell('ref'=>merged_cell[:attributes][:ref].to_s)
157
+ end
158
+ }
159
+ end
160
+
161
+ xml.phoneticPr('fontId'=>'1','type'=>'noConversion')
162
+
163
+ unless @worksheet.validations.nil?
164
+ xml.dataValidations('count'=>@worksheet.validations.size.to_s) {
165
+ @worksheet.validations.each do |validation|
166
+ xml.dataValidation('type'=>validation[:attributes][:type],
167
+ 'sqref'=>validation[:attributes][:sqref],
168
+ 'allowBlank'=>Integer(validation[:attributes][:allowBlank]).to_s,
169
+ 'showInputMessage'=>Integer(validation[:attributes][:showInputMessage]).to_s,
170
+ 'showErrorMessage'=>Integer(validation[:attributes][:showErrorMessage]).to_s) {
171
+ unless validation[:formula1].nil?
172
+ xml.formula1 validation[:formula1]
173
+ end
174
+ }
175
+ end
176
+ }
177
+ end
178
+
179
+ xml.pageMargins('left'=>'0.75','right'=>'0.75','top'=>'1',
180
+ 'bottom'=>'1','header'=>'0.5','footer'=>'0.5')
181
+
182
+ xml.pageSetup('orientation'=>'portrait',
183
+ 'horizontalDpi'=>'4294967292', 'verticalDpi'=>'4294967292')
184
+
185
+ unless @worksheet.legacy_drawing.nil?
186
+ xml.legacyDrawing('r:id'=>@worksheet.legacy_drawing[:attributes][:id])
187
+ end
188
+
189
+ unless @worksheet.extLst.nil?
190
+ xml.extLst {
191
+ xml.ext('xmlns:mx'=>"http://schemas.microsoft.com/office/mac/excel/2008/main",
192
+ 'uri'=>"http://schemas.microsoft.com/office/mac/excel/2008/main") {
193
+ xml['mx'].PLV('Mode'=>'1', 'OnePage'=>'0','WScale'=>'0')
194
+ }
195
+ }
196
+ end
197
+ }
198
+ end
199
+ contents = builder.to_xml
200
+ contents = contents.gsub(/\n/,'')
201
+ contents = contents.gsub(/>(\s)+</,'><')
202
+ contents = contents.sub(/<\?xml version=\"1.0\"\?>/,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\n")
203
+ contents
204
+ end
205
+
206
+ end
207
+ end
208
+ 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
Binary file
@@ -0,0 +1,106 @@
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{rubyXL}
8
+ s.version = "1.0.4"
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{2011-08-01}
13
+ s.description = %q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx) Documents}
14
+ s.email = %q{bhagwat.vivek@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/.DS_Store",
29
+ "lib/Hash.rb",
30
+ "lib/cell.rb",
31
+ "lib/color.rb",
32
+ "lib/parser.rb",
33
+ "lib/private_class.rb",
34
+ "lib/rubyXL.rb",
35
+ "lib/test.html",
36
+ "lib/tests/test.rb",
37
+ "lib/tests/test10.rb",
38
+ "lib/tests/test2.rb",
39
+ "lib/tests/test3.rb",
40
+ "lib/tests/test4.rb",
41
+ "lib/tests/test5.rb",
42
+ "lib/tests/test6.rb",
43
+ "lib/tests/test7.rb",
44
+ "lib/tests/test8.rb",
45
+ "lib/tests/test9.rb",
46
+ "lib/workbook.rb",
47
+ "lib/worksheet.rb",
48
+ "lib/writer/app_writer.rb",
49
+ "lib/writer/calc_chain_writer.rb",
50
+ "lib/writer/content_types_writer.rb",
51
+ "lib/writer/core_writer.rb",
52
+ "lib/writer/root_rels_writer.rb",
53
+ "lib/writer/shared_strings_writer.rb",
54
+ "lib/writer/styles_writer.rb",
55
+ "lib/writer/theme_writer.rb",
56
+ "lib/writer/workbook_rels_writer.rb",
57
+ "lib/writer/workbook_writer.rb",
58
+ "lib/writer/worksheet_writer.rb",
59
+ "lib/zip.rb",
60
+ "pkg/rubyXL-1.0.4.gem",
61
+ "rubyXL.gemspec",
62
+ "spec/lib/cell_spec.rb",
63
+ "spec/lib/color_spec.rb",
64
+ "spec/lib/hash_spec.rb",
65
+ "spec/lib/parser_spec.rb",
66
+ "spec/lib/workbook_spec.rb",
67
+ "spec/lib/worksheet_spec.rb"
68
+ ]
69
+ s.homepage = %q{http://github.com/vivekbhagwat/rubyXL}
70
+ s.licenses = ["MIT"]
71
+ s.require_paths = ["lib"]
72
+ s.rubygems_version = %q{1.3.7}
73
+ s.summary = %q{rubyXL is a gem which allows the parsing, creation, and manipulation of Microsoft Excel (.xlsx) Documents}
74
+
75
+ if s.respond_to? :specification_version then
76
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
77
+ s.specification_version = 3
78
+
79
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
80
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
81
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
82
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
83
+ s.add_development_dependency(%q<rcov>, [">= 0"])
84
+ s.add_development_dependency(%q<nokogiri>, [">= 1.4.4"])
85
+ s.add_development_dependency(%q<rubyzip>, [">= 0.9.4"])
86
+ s.add_development_dependency(%q<rspec>, [">= 1.3.4"])
87
+ else
88
+ s.add_dependency(%q<shoulda>, [">= 0"])
89
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
90
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
91
+ s.add_dependency(%q<rcov>, [">= 0"])
92
+ s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
93
+ s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
94
+ s.add_dependency(%q<rspec>, [">= 1.3.4"])
95
+ end
96
+ else
97
+ s.add_dependency(%q<shoulda>, [">= 0"])
98
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
99
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
100
+ s.add_dependency(%q<rcov>, [">= 0"])
101
+ s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
102
+ s.add_dependency(%q<rubyzip>, [">= 0.9.4"])
103
+ s.add_dependency(%q<rspec>, [">= 1.3.4"])
104
+ end
105
+ end
106
+
@@ -0,0 +1,359 @@
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 '.change_contents' do
196
+ it 'should cause cell value to match string or number that is passed in' do
197
+ @cell.change_contents('TEST')
198
+ @cell.value.should == 'TEST'
199
+ @cell.formula.should == nil
200
+ end
201
+
202
+ it 'should cause cell value and formula to match what is passed in' do
203
+ @cell.change_contents(nil, 'SUM(A2:A4)')
204
+ @cell.value.should == nil
205
+ @cell.formula.should == 'SUM(A2:A4)'
206
+ end
207
+ end
208
+
209
+ describe '.is_italicized' do
210
+ it 'should correctly return whether or not the cell\'s font is italicized' do
211
+ @cell.change_font_italics(true)
212
+ @cell.is_italicized.should == true
213
+ end
214
+ end
215
+
216
+ describe '.is_bolded' do
217
+ it 'should correctly return whether or not the cell\'s font is bolded' do
218
+ @cell.change_font_bold(true)
219
+ @cell.is_bolded.should == true
220
+ end
221
+ end
222
+
223
+ describe '.is_underlined' do
224
+ it 'should correctly return whether or not the cell\'s font is underlined' do
225
+ @cell.change_font_underline(true)
226
+ @cell.is_underlined.should == true
227
+ end
228
+ end
229
+
230
+ describe '.is_struckthrough' do
231
+ it 'should correctly return whether or not the cell\'s font is struckthrough' do
232
+ @cell.change_font_strikethrough(true)
233
+ @cell.is_struckthrough.should == true
234
+ end
235
+ end
236
+
237
+ describe '.font_name' do
238
+ it 'should correctly return the name of the cell\'s font' do
239
+ @cell.change_font_name('Verdana')
240
+ @cell.font_name.should == 'Verdana'
241
+ end
242
+ end
243
+
244
+ describe '.font_size' do
245
+ it 'should correctly return the size of the cell\'s font' do
246
+ @cell.change_font_size(20)
247
+ @cell.font_size.should == 20
248
+ end
249
+ end
250
+
251
+ describe '.font_color' do
252
+ it 'should correctly return the color of the cell\'s font' do
253
+ @cell.change_font_color('0f0f0f')
254
+ @cell.font_color.should == '0f0f0f'
255
+ end
256
+
257
+ it 'should return 000000 (black) if no font color has been specified for this cell' do
258
+ @cell.font_color.should == '000000'
259
+ end
260
+ end
261
+
262
+ describe '.fill_color' do
263
+ it 'should correctly return the color of the cell\'s fill' do
264
+ @cell.change_fill('000000')
265
+ @cell.fill_color.should == '000000'
266
+ end
267
+
268
+ it 'should return ffffff (white) if no fill color has been specified for this cell' do
269
+ @cell.fill_color.should == 'ffffff'
270
+ end
271
+ end
272
+
273
+ describe '.horizontal_alignment' do
274
+ it 'should correctly return the type of horizontal alignment of this cell' do
275
+ @cell.change_horizontal_alignment('center')
276
+ @cell.horizontal_alignment.should == 'center'
277
+ end
278
+
279
+ it 'should return nil if no horizontal alignment has been specified for this cell' do
280
+ @cell.horizontal_alignment.should == nil
281
+ end
282
+ end
283
+
284
+ describe '.vertical_alignment' do
285
+ it 'should correctly return the type of vertical alignment of this cell' do
286
+ @cell.change_vertical_alignment('center')
287
+ @cell.vertical_alignment.should == 'center'
288
+ end
289
+
290
+ it 'should return nil if no vertical alignment has been specified for this cell' do
291
+ @cell.vertical_alignment.should be_nil
292
+ end
293
+ end
294
+
295
+ describe '.border_top' do
296
+ it 'should correctly return the weight of the border on top for this cell' do
297
+ @cell.change_border_top('thin')
298
+ @cell.border_top.should == 'thin'
299
+ end
300
+
301
+ it 'should return nil if no top border has been specified for this cell' do
302
+ @cell.border_top.should be_nil
303
+ end
304
+ end
305
+
306
+ describe '.border_left' do
307
+ it 'should correctly return the weight of the border on left for this cell' do
308
+ @cell.change_border_left('thin')
309
+ @cell.border_left.should == 'thin'
310
+ end
311
+
312
+ it 'should return nil if no left border has been specified for this cell' do
313
+ @cell.border_left.should be_nil
314
+ end
315
+ end
316
+
317
+ describe '.border_right' do
318
+ it 'should correctly return the weight of the border on right for this cell' do
319
+ @cell.change_border_right('thin')
320
+ @cell.border_right.should == 'thin'
321
+ end
322
+
323
+ it 'should return nil if no right border has been specified for this cell' do
324
+ @cell.border_right.should be_nil
325
+ end
326
+ end
327
+
328
+ describe '.border_bottom' do
329
+ it 'should correctly return the weight of the border on bottom for this cell' do
330
+ @cell.change_border_bottom('thin')
331
+ @cell.border_bottom.should == 'thin'
332
+ end
333
+
334
+ it 'should return nil if no bottom border has been specified for this cell' do
335
+ @cell.border_bottom.should be_nil
336
+ end
337
+ end
338
+
339
+ describe '.border_diagonal' do
340
+ it 'should correctly return the weight of the diagonal border for this cell' do
341
+ @cell.change_border_diagonal('thin')
342
+ @cell.border_diagonal.should == 'thin'
343
+ end
344
+
345
+ it 'should return nil if no diagonal border has been specified for this cell' do
346
+ @cell.border_diagonal.should be_nil
347
+ end
348
+ end
349
+
350
+ describe '.convert_to_cell' do
351
+ it 'should correctly return the "Excel Style" description of cells when given a row/column number' do
352
+ RubyXL::Cell.convert_to_cell(0,26).should == 'AA1'
353
+ end
354
+
355
+ it 'should cause an error if a negative argument is given' do
356
+ lambda {RubyXL::Cell.convert_to_cell(-1,0)}.should raise_error
357
+ end
358
+ end
359
+ end