rspreadsheet 0.4.7 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdaab0a6bad4e406aa6e180c1a0b5d21d7f1e01586d0275449e6a824852d07c6
4
- data.tar.gz: 83f64bbd8b7c94c924ce0b75794995c4f90f2d14630f5a87b2f96d2fae80a6cc
3
+ metadata.gz: b2c92247a04812100d02a3145ee69d112aa434b6ea2365c6f416a7be5d399eef
4
+ data.tar.gz: 728f3fb25da67aa9cd4b31f5d1ddec687b9ddc7bc749f6baefe4bb926048b2ca
5
5
  SHA512:
6
- metadata.gz: 324d95798062e62cdb99a8039b48e46b80ddd33c31a6963e6c51af5da01f0858db51fd737937b1744b33d8b085a4b03e0ed81c92d4523e20a961ba7c437bda55
7
- data.tar.gz: 60445dbdb2965e661db8e0b1213039aa89ad0b8a53ac61de4aa7e2005a9b4274bfd8bdad66cc6a494f4bc331e06c0f2012eab2150787859e018f977e6fd68214
6
+ metadata.gz: 73dc5875e271ff2fd0e67997ced78078538147d8beeec3c2d61e3eb2bcde0f60a3b80a758f1e1e396c76347fea2bfe1d1db0a727c13d75f8e01218291010a5b3
7
+ data.tar.gz: 637a92a312e621f4482499bfb27235ffcdb57e8a936834b7f492024b67284a8b89884429c6eaf40cb94a67b523a6b52f7b4479c6d1f672e649635c5ec551ef89
@@ -9,6 +9,8 @@ After you have cloned the source run `bundle` command in gem directory to instal
9
9
 
10
10
  ## Ideas/wishlist
11
11
 
12
+ * refactor Style and AutomaticStyle objects from CellFormat.
13
+ * introduce "speedup" option, which can for example skip all "safetest" (or it can be named $prudent = true/false)
12
14
  * make it configurable whether Time or DateTime will be used.
13
15
  * In future inntroduce syntax like `sheet.range('C3:E4')` for mass operations.
14
16
  * Trying to make row Enumerable - perhaps skipping empty or undefined cells.
data/GUIDE.md CHANGED
@@ -3,42 +3,42 @@
3
3
 
4
4
  You can open ODS file (OpenDocument Spreadsheet) like this
5
5
  ````ruby
6
- @workbook = Rspreadsheet.open('./test.ods')
6
+ workbook = Rspreadsheet.open('./test.ods')
7
7
  ````
8
8
  and access its first sheet like this
9
9
  ````ruby
10
- @sheet = @workbook.worksheet(1)
10
+ sheet = workbook.worksheet(1)
11
11
  ````
12
12
  ### Accessing cells
13
13
 
14
14
  you can get and set contents of cells using "verbatim" syntax like
15
15
  ````ruby
16
- @sheet.row(5).cell(4).value
17
- @sheet.row(5).cell(4).value = 10
16
+ sheet.row(5).cell(4).value
17
+ sheet.row(5).cell(4).value = 10
18
18
  ````
19
19
  or using "brief" syntax like
20
20
  ````ruby
21
- @sheet[5,4]
22
- @sheet[5,4] = 10
21
+ sheet[5,4]
22
+ sheet[5,4] = 10
23
23
  ````
24
24
 
25
25
  You can mix these two at will, for example like this
26
26
  ````ruby
27
- @row = @sheet.row(5)
28
- @row[4] = 10
27
+ row = sheet.row(5)
28
+ row[4] = 10
29
29
  ````
30
30
 
31
31
  ### Working with images
32
- @sheet.insert_image_to('10.21mm','15mm','image.png')
33
- i = @sheet.images.first
32
+ sheet.insert_image_to('10.21mm','15mm','image.png')
33
+ i = sheet.images.first
34
34
  i.move_to('100mm','99.98mm')
35
35
 
36
36
  ### Saving
37
37
  The file needs to be saved after doing changes.
38
38
  ````ruby
39
- @workbook.save
40
- @workbook.save('new_filename.ods') # changes filename and saves
41
- @workbook.save(any_io_object) # file can be saved to any IO like object as well
39
+ workbook.save
40
+ workbook.save('new_filename.ods') # changes filename and saves
41
+ workbook.save(any_io_object) # file can be saved to any IO like object as well
42
42
  ````
43
43
  ### Date and Time
44
44
  OpenDocument and ruby have different models of date, time and datetime. Ruby containg three different objects. Time and DateTime cover all cases, Date covers dates only. OpenDocument distinguishes two groups - time of a day (time) and everything else (date). To simplify things a little we return cell values containg time of day as Time object and cell values containg datetime of date as DateTime. I am aware that this is very arbitrary choice, but it is very practical. This way and to some extend the types of values from OpenDocument are preserved when read from files, beeing acted upon and written back to spreadshhet.
@@ -54,5 +54,5 @@ OpenDocument and ruby have different models of date, time and datetime. Ruby con
54
54
  * with numeric coordinates row always comes before col as in (row,col)
55
55
  * with alphanumerical col always comes before row as in F12
56
56
  * Shorter syntax worksheet[x,y] returns value, longer syntax worksheet.cell(x,y) return cell objects. This allows to work conviniently with values using short syntax and access the cell object if needed (to access formatting for example).
57
- * Note: currently plural and singular like sheet/sheets, row/rows, cell/cells can be used intergangebly, but there is a (discussion)[https://github.com/gorn/rspreadsheet/issues/10] about this and in future versions we might use singular style for methods and plural for array style.
57
+ * Singular and plural like sheet/sheets, row/rows, cell/cells can be used intergangebly.
58
58
 
@@ -2,14 +2,6 @@
2
2
  # @author Jakub Tesinsky
3
3
  # @title rspreadsheet Cell
4
4
 
5
- # require 'andand'
6
- # require 'rspreadsheet/xml_tied_item'
7
- # require 'date'
8
- # require 'time' # extended functions for time like Time.strptime
9
- # require 'bigdecimal'
10
- # require 'bigdecimal/util' # for to_d method
11
- # require 'helpers/class_extensions'
12
-
13
5
  module Rspreadsheet
14
6
  using ClassExtensions if RUBY_VERSION > '2.1'
15
7
 
@@ -28,43 +20,73 @@ class CellFormat
28
20
  end
29
21
  def cellnode; @cell.xmlnode end
30
22
 
31
- # text style attribute readers
23
+ # @!group text style attribute readers
32
24
  def bold; get_text_style_node_attribute('font-weight') == 'bold' end
33
25
  alias :bold? :bold
34
26
  def italic; get_text_style_node_attribute('font-style') == 'italic' end
35
27
  def color; get_text_style_node_attribute('color') end
36
28
  def font_size; get_text_style_node_attribute('font-size') end
37
- def get_text_style_node_attribute(attribute_name)
38
- text_style_node.nil? ? nil : Tools.get_ns_attribute_value(text_style_node,'fo',attribute_name)
39
- end
40
29
  def background_color; get_cell_style_node_attribute('background-color') end
41
- def get_cell_style_node_attribute(attribute_name)
42
- cell_style_node.nil? ? nil : Tools.get_ns_attribute_value(cell_style_node,'fo',attribute_name)
30
+ def currency
31
+ Tools.get_ns_attribute_value(cellnode,'office','currency',nil)
43
32
  end
44
33
 
45
- # text style attribute writers
34
+ # @!group text style attribute writers
46
35
  def bold=(value); set_text_style_node_attribute('font-weight', value ? 'bold' : 'normal') end
47
36
  def italic=(value); set_text_style_node_attribute('font-style', value ? 'italic' : 'normal') end
48
37
  def color=(value); set_text_style_node_attribute('color', value) end
49
38
  def font_size=(value);set_text_style_node_attribute('font-size', value) end
39
+ def background_color=(value); set_cell_style_node_attribute('background-color', value) end
40
+
41
+
42
+ # @!group border related
43
+ def top; @top ||= Border.new(self,:top) end
44
+ def bottom; @bottom ||= Border.new(self,:bottom) end
45
+ def left; @left ||= Border.new(self,:left) end
46
+ def right; @right ||= Border.new(self,:right) end
47
+ alias :border_top :top
48
+ alias :border_right :right
49
+ alias :border_bottom :bottom
50
+ alias :border_left :left
51
+
52
+ # @!group manipulation of style related nodes
53
+ def get_text_style_node_attribute(attribute_name)
54
+ text_style_node.nil? ? nil : Tools.get_ns_attribute_value(text_style_node,'fo',attribute_name)
55
+ end
56
+ def get_cell_style_node_attribute(attribute_name)
57
+ cell_style_node.nil? ? nil : Tools.get_ns_attribute_value(cell_style_node,'fo',attribute_name)
58
+ end
50
59
  def set_text_style_node_attribute(attribute_name,value)
51
- @cell.detach if @cell.mode != :regular
60
+ make_sure_styles_are_not_shared
52
61
  if text_style_node.nil?
53
62
  self.create_text_style_node
54
- raise 'Style node was not correctly initialized' if text_style_node.nil?
63
+ raise 'Text style node was not correctly initialized' if text_style_node.nil?
55
64
  end
56
65
  Tools.set_ns_attribute(text_style_node,'fo',attribute_name,value)
57
66
  end
58
- def background_color=(value); set_cell_style_node_attribute('background-color', value) end
59
67
  def set_cell_style_node_attribute(attribute_name,value)
60
- @cell.detach if @cell.mode != :regular
68
+ make_sure_styles_are_not_shared
61
69
  if cell_style_node.nil?
62
70
  self.create_cell_style_node
63
- raise 'Style node was not correctly initialized' if cell_style_node.nil?
71
+ raise 'Cell style node was not correctly initialized' if cell_style_node.nil?
64
72
  end
65
73
  Tools.set_ns_attribute(cell_style_node,'fo',attribute_name,value)
66
74
  end
67
-
75
+ def make_sure_styles_are_not_shared # with another cell (prevent issue #40)
76
+ # if cell is reapeated, we must detach it first
77
+ @cell.detach if @cell.mode != :regular
78
+ # if style node is shared, we must create our own first
79
+ if style_shared?
80
+ new_style_name = unused_cell_style_name
81
+
82
+ new_style_node = style_node.copy(true)
83
+ Tools.set_ns_attribute(new_style_node,'style','name',new_style_name)
84
+ style_node.next = new_style_node
85
+ self.style_name = new_style_name
86
+ raise 'Unsucessfull unsharing of styles' if style_shared?
87
+ end
88
+ end
89
+
68
90
  # @!group initialization of style related nodes, if they do not exist
69
91
  def create_text_style_node
70
92
  create_style_node if style_name.nil? or style_node.nil?
@@ -83,13 +105,14 @@ class CellFormat
83
105
  raise 'Style name was not correctly initialized' if style_name!=proposed_style_name
84
106
  end
85
107
  anode = Tools.prepare_ns_node('style','style')
86
- Tools.set_ns_attribute(anode, 'style', 'name', proposed_style_name)
108
+ Tools.set_ns_attribute(anode, 'style', 'name', style_name)
87
109
  Tools.set_ns_attribute(anode, 'style', 'family', 'table-cell')
88
110
  Tools.set_ns_attribute(anode, 'style', 'parent-style-name', 'Default')
89
111
  automatic_styles_node << anode
90
112
  raise 'Style node was not correctly initialized' if style_node.nil?
91
113
  end
92
114
 
115
+ # @!group other style node related routines
93
116
  def unused_cell_style_name
94
117
  last = (cellnode.nil? ? [] : cellnode.doc.root.find('./office:automatic-styles/style:style')).
95
118
  collect {|node| node['name']}.
@@ -106,27 +129,25 @@ class CellFormat
106
129
  return nil if cellnode.nil?
107
130
  cellnode.doc.root.find("./office:automatic-styles#{xpath}").first
108
131
  end
109
- def currency
110
- Tools.get_ns_attribute_value(cellnode,'office','currency',nil)
132
+
133
+ # how many cells are using this style. repeated cells are counted only once
134
+ def style_shared_count
135
+ cellnode.doc.root.find("//table:table-cell[@table:style-name=\"#{style_name}\"]").size
136
+ end
137
+ def style_shared?
138
+ style_shared_count>1
111
139
  end
112
- #returns object representing top border of the cell
113
- def top; @top ||= Border.new(self,:top) end
114
- def bottom; @bottom ||= Border.new(self,:bottom) end
115
- def left; @left ||= Border.new(self,:left) end
116
- def right; @right ||= Border.new(self,:right) end
117
- alias :border_top :top
118
- alias :border_right :right
119
- alias :border_bottom :bottom
120
- alias :border_left :left
121
140
 
141
+ # @!group other routines
122
142
  def inspect
123
- "#<Rspreadsheet::CellFormat bold:#{bold?.inspect}, borders:#{top.get_value_string.inspect} #{right.get_value_string.inspect} #{bottom.get_value_string.inspect} #{left.get_value_string.inspect}>"
143
+ "#<Rspreadsheet::CellFormat bold:#{bold?.inspect}, borders: #{top.get_border_string || 'none'}, #{right.get_border_string || 'none'}, #{bottom.get_border_string || 'none'}, #{left.get_border_string || 'none'}>"
124
144
  end
125
- # experimental. Allows to assign a style to cell.
145
+
146
+ # experimental. Allows to assign a style to cell. Currenty used only for automatic styles.
126
147
  def style_name=(value)
127
- Tools.set_ns_attribute_value(cellnode,'table','style-name',value)
148
+ Tools.set_ns_attribute(cellnode,'table','style-name',value)
128
149
  end
129
-
150
+
130
151
  end
131
152
 
132
153
  # represents one of the borders of a cell
@@ -148,11 +169,10 @@ class Border
148
169
  def delete
149
170
  @cellformat.set_cell_style_node_attribute(attribute_name, 'none')
150
171
  end
151
-
152
-
172
+
153
173
  ## internals
154
174
 
155
- # set parth-th part of string which represents the border. String looks like "0.06pt solid #00ee00"
175
+ # set part-th part of string which represents the border. String looks like "0.06pt solid #00ee00"
156
176
  # part is 1 for width, 2 for style or 3 for color
157
177
  def set_border_string_part(part,value)
158
178
  current_value = @cellformat.get_cell_style_node_attribute(attribute_name)
@@ -167,19 +187,19 @@ class Border
167
187
  @cellformat.set_cell_style_node_attribute(attribute_name, value_array.join(' '))
168
188
  end
169
189
 
170
- def get_border_string_part(part)
171
- current_value = @cellformat.get_cell_style_node_attribute(attribute_name) || @cellformat.get_cell_style_node_attribute('border')
172
- if current_value.nil? or (current_value=='none')
173
- return nil
174
- else
175
- value_array = current_value.split(' ')
176
- raise 'Strange border attribute value. Does not have 3 parts' unless value_array.length == 3
177
- return value_array[part-1]
178
- end
190
+ def get_border_string
191
+ result = @cellformat.get_cell_style_node_attribute(attribute_name) || @cellformat.get_cell_style_node_attribute('border')
192
+ result = nil if result=='none'
193
+ result
179
194
  end
180
195
 
181
- def get_value_string
182
- @cellformat.get_cell_style_node_attribute(attribute_name)
196
+ def get_border_string_part(part)
197
+ border_string = get_border_string
198
+ return nil if border_string.nil?
199
+
200
+ value_array = border_string.split(' ')
201
+ raise 'Strange border attribute value. Does not have 3 parts' unless value_array.length == 3
202
+ return value_array[part-1]
183
203
  end
184
204
 
185
205
  end
@@ -1,3 +1,3 @@
1
1
  module Rspreadsheet
2
- VERSION = "0.4.7"
2
+ VERSION = "0.4.8"
3
3
  end
@@ -7,7 +7,7 @@ using ClassExtensions if RUBY_VERSION > '2.1'
7
7
 
8
8
 
9
9
  # Abstract class similar to XMLTiedArray but with support to "repeatable" items. This is notion specific
10
- # to OpenDocument files - whnewer a row repeats more times (or a cell), one can either make many identical
10
+ # to OpenDocument files - whenewer a row repeats more times (or a cell), one can either make many identical
11
11
  # copies of the same xml or only make one xml representing one item and add attribute xml_repeated.
12
12
  #
13
13
  # This class is made to be included, not subclassed - the reason is in delete method which calls super.
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+
3
+ # tests for graphical formats (value formats are elsewhere)
4
+ describe Rspreadsheet::Cell do
5
+ before do
6
+ book1 = Rspreadsheet.new
7
+ @sheet1 = book1.create_worksheet
8
+ book2 = Rspreadsheet.new($test_filename)
9
+ @sheet2 = book2.worksheets(1)
10
+ end
11
+ it 'can have different formats' do
12
+ @cell = @sheet2.cell(6,3)
13
+ @cell.format.bold.should == true
14
+ @cell = @sheet2.cell(6,4)
15
+ @cell.format.bold.should == false
16
+ @cell.format.italic.should == true
17
+ @cell = @sheet2.cell(6,5)
18
+ @cell.format.italic.should == false
19
+ @cell.format.color.should == '#ff3333'
20
+ @cell = @sheet2.cell(6,6)
21
+ @cell.format.color.should_not == '#ff3333'
22
+ @cell.format.background_color.should == '#6666ff'
23
+ @cell = @sheet2.cell(6,7)
24
+ @cell.format.font_size.should == '7pt'
25
+
26
+ # after fresh create
27
+ @cell.xmlnode.attributes['style-name'].should_not be_nil
28
+ end
29
+ it 'can set formats of the cell in new file' do
30
+ @cell = @sheet1.cell(1,1)
31
+ @cell.value = '1'
32
+ # bold
33
+ @cell.format.bold.should be_falsey
34
+ @cell.format.bold = true
35
+ @cell.format.bold.should be_truthy
36
+ # italic
37
+ @cell.format.italic.should be_falsey
38
+ @cell.format.italic = true
39
+ @cell.format.italic.should be_truthy
40
+ # color
41
+ @cell.format.color.should be_nil
42
+ @cell.format.color = '#AABBCC'
43
+ @cell.format.color.should eq '#AABBCC'
44
+ # background_color
45
+ @cell.format.background_color.should be_nil
46
+ @cell.format.background_color = '#AABBCC'
47
+ @cell.format.style_name.should_not eq 'cell'
48
+ @cell.format.background_color.should eq '#AABBCC'
49
+ # font_size
50
+ @cell.format.font_size.should be_nil
51
+ @cell.format.font_size = '11pt'
52
+ @cell.format.font_size.should eq '11pt'
53
+ end
54
+ it 'setting format in new file detaches the cell' do
55
+ @cell = @sheet1.cell(1,1)
56
+ # bold
57
+ @cell.format.bold.should be_falsey
58
+ @cell.format.bold = true
59
+ @cell.format.bold.should be_truthy
60
+ @cell.mode.should eq :regular
61
+
62
+ @cell = @sheet1.cell(2,2)
63
+ @cell.format.background_color = '#ffeeaa'
64
+ @cell.format.background_color.should == '#ffeeaa'
65
+ @cell.mode.should eq :regular
66
+ end
67
+ it 'is possible to manipulate borders of cells' do
68
+ @cell = @sheet1.cell(1,1)
69
+
70
+ [@cell.format.top,@cell.format.left,@cell.format.right,@cell.format.bottom].each do |border|
71
+ border.style = 'dashed'
72
+ border.style.should == 'dashed'
73
+ border.width = 0.5
74
+ border.width.should == 0.5
75
+ border.color = '#005500'
76
+ border.color.should == '#005500'
77
+ end
78
+ end
79
+ it 'returns correct border parameters for the cell' do
80
+ @sheet2.cell('C8').format.top.style.should == 'solid'
81
+ @sheet2.cell('E8').format.left.color.should == '#ff3333'
82
+ @sheet2.cell('E8').format.left.style.should == 'solid'
83
+ @sheet2.cell('F8').format.top.color.should == '#009900'
84
+ @sheet2.cell('F8').format.top.style.should == 'dotted'
85
+ end
86
+ it 'modifies borders correctly' do
87
+ ## initially solid everywhere
88
+ @sheet2.cell('C8').format.top.style.should == 'solid'
89
+ @sheet2.cell('C8').format.bottom.style.should == 'solid'
90
+ @sheet2.cell('C8').format.left.style.should == 'solid'
91
+ @sheet2.cell('C8').format.right.style.should == 'solid'
92
+ ## change top and right to dotted and observe
93
+ @sheet2.cell('C8').format.top.style = 'dotted'
94
+ @sheet2.cell('C8').format.right.style = 'dotted'
95
+ @sheet2.cell('C8').format.bottom.style.should == 'solid'
96
+ @sheet2.cell('C8').format.left.style.should == 'solid'
97
+ @sheet2.cell('C8').format.top.style.should == 'dotted'
98
+ @sheet2.cell('C8').format.right.style.should == 'dotted'
99
+ end
100
+ it 'deletes borders correctly', :pending=> 'consider how to deal with deleted borders' do
101
+ @cell = @sheet1.cell(1,1)
102
+
103
+ [@cell.format.top,@cell.format.left,@cell.format.right,@cell.format.bottom].each do |border|
104
+ border.style = 'dashed'
105
+ border.should_not be_nil
106
+ border.delete
107
+ border.should be_nil
108
+ end
109
+
110
+ # delete right border in existing file and observe
111
+ @sheet2.cell('C8').format.right.delete
112
+ @sheet2.cell('C8').format.right.should == nil
113
+ end
114
+
115
+ it 'can delete borders in many ways', :pending => 'consider what syntax to support' do
116
+ @cell=@sheet2.cell('C8')
117
+ @cell.border_right.should_not be_nil
118
+ @cell.border_right.delete
119
+ @cell.border_right.should be_nil
120
+
121
+ @cell.border_left.should_not be_nil
122
+ @cell.border_left = nil
123
+ @cell.border_left.should be_nil
124
+
125
+ @cell.format.top.should_not_be_nil
126
+ @cell.format.top.style = 'none'
127
+ @cell.border_top.should_not be_nil ## ?????
128
+ end
129
+
130
+ it 'does not have issue 40 - coloring other cells, when they have similar borders' do
131
+ sheet = Rspreadsheet.open('./spec/testfile-issue-40.ods').worksheet(1)
132
+ sheet[1,1] = 'ahoj'
133
+ sheet.cell(1,1).format.background_color = '#FF0000'
134
+
135
+ sheet.cell(1,1).format.background_color.should == '#FF0000'
136
+ sheet.cell('B3').format.background_color.should_not == '#FF0000'
137
+ end
138
+
139
+ it 'automatically creates new style, if a style is automatic, some of its attributes changes and there are several cells pointing to it', :focus do
140
+ sheet = Rspreadsheet.open('./spec/testfile-issue-40.ods').worksheet(1)
141
+ cell1 = sheet.cell(1,1)
142
+ cell2 = sheet.cell('B3')
143
+
144
+ cell1.xmlnode.attributes['style-name'].should == cell2.xmlnode.attributes['style-name']
145
+ cell1.format.background_color = '#FF0000'
146
+
147
+ cell1.xmlnode.attributes['style-name'].should_not == cell2.xmlnode.attributes['style-name']
148
+ end
149
+
150
+ it 'recognizes correctly that style is shared with other cell' do
151
+ sheet = Rspreadsheet.open('./spec/testfile-issue-40.ods').worksheet(1)
152
+
153
+ sheet.cell(1,1).format.style_shared_count.should == 2
154
+ sheet.cell(1,1).format.style_shared?.should == true
155
+ end
156
+
157
+ end
@@ -182,49 +182,6 @@ describe Rspreadsheet::Cell do
182
182
  @sheet2.insert_cell_before(1,1)
183
183
  @sheet2.rows(1).cell(1).should be_kind_of(Rspreadsheet::Cell)
184
184
  end
185
- it 'can have different formats' do
186
- @cell = @sheet2.cell(6,3)
187
- @cell.format.bold.should == true
188
- @cell = @sheet2.cell(6,4)
189
- @cell.format.bold.should == false
190
- @cell.format.italic.should == true
191
- @cell = @sheet2.cell(6,5)
192
- @cell.format.italic.should == false
193
- @cell.format.color.should == '#ff3333'
194
- @cell = @sheet2.cell(6,6)
195
- @cell.format.color.should_not == '#ff3333'
196
- @cell.format.background_color.should == '#6666ff'
197
- @cell = @sheet2.cell(6,7)
198
- @cell.format.font_size.should == '7pt'
199
-
200
- # after fresh create
201
- @cell.xmlnode.attributes['style-name'].should_not be_nil
202
- end
203
- it 'can set formats of the cell in new file' do
204
- @cell = @sheet1.cell(1,1)
205
- @cell.value = '1'
206
- # bold
207
- @cell.format.bold.should be_falsey
208
- @cell.format.bold = true
209
- @cell.format.bold.should be_truthy
210
- # italic
211
- @cell.format.italic.should be_falsey
212
- @cell.format.italic = true
213
- @cell.format.italic.should be_truthy
214
- # color
215
- @cell.format.color.should be_nil
216
- @cell.format.color = '#AABBCC'
217
- @cell.format.color.should eq '#AABBCC'
218
- # background_color
219
- @cell.format.background_color.should be_nil
220
- @cell.format.background_color = '#AABBCC'
221
- @cell.format.style_name.should_not eq 'cell'
222
- @cell.format.background_color.should eq '#AABBCC'
223
- # font_size
224
- @cell.format.font_size.should be_nil
225
- @cell.format.font_size = '11pt'
226
- @cell.format.font_size.should eq '11pt'
227
- end
228
185
  it 'method cells without arguments returns array of cells' do
229
186
  @a = @sheet2.rows(1).cells
230
187
  @a.should be_kind_of(Array)
@@ -326,19 +283,6 @@ describe Rspreadsheet::Cell do
326
283
  @sheet2.cell('BA177').should be @sheet2.cell(177,53)
327
284
  @sheet2.cell('ADA2').should be @sheet2.cell(2,781)
328
285
  end
329
- it 'setting format in new file detaches the cell' do
330
- @cell = @sheet1.cell(1,1)
331
- # bold
332
- @cell.format.bold.should be_falsey
333
- @cell.format.bold = true
334
- @cell.format.bold.should be_truthy
335
- @cell.mode.should eq :regular
336
-
337
- @cell = @sheet1.cell(2,2)
338
- @cell.format.background_color = '#ffeeaa'
339
- @cell.format.background_color.should == '#ffeeaa'
340
- @cell.mode.should eq :regular
341
- end
342
286
  it 'remembers formula when set' do
343
287
  @cell = @sheet1.cell(1,1)
344
288
  @cell.formula.should be_nil
@@ -386,72 +330,6 @@ describe Rspreadsheet::Cell do
386
330
  @cell.type.should eq :currency
387
331
  @cell.format.currency.should == 'CZK'
388
332
  end
389
- it 'is possible to manipulate borders of cells' do
390
- @cell = @sheet1.cell(1,1)
391
-
392
- [@cell.format.top,@cell.format.left,@cell.format.right,@cell.format.bottom].each do |border|
393
- border.style = 'dashed'
394
- border.style.should == 'dashed'
395
- border.width = 0.5
396
- border.width.should == 0.5
397
- border.color = '#005500'
398
- border.color.should == '#005500'
399
- end
400
- end
401
- it 'returns correct border parameters for the cell' do
402
- @sheet2.cell('C8').format.top.style.should == 'solid'
403
- @sheet2.cell('E8').format.left.color.should == '#ff3333'
404
- @sheet2.cell('E8').format.left.style.should == 'solid'
405
- @sheet2.cell('F8').format.top.color.should == '#009900'
406
- @sheet2.cell('F8').format.top.style.should == 'dotted'
407
- end
408
- it 'modifies borders correctly' do
409
- ## initially solid everywhere
410
- @sheet2.cell('C8').format.top.style.should == 'solid'
411
- @sheet2.cell('C8').format.bottom.style.should == 'solid'
412
- @sheet2.cell('C8').format.left.style.should == 'solid'
413
- @sheet2.cell('C8').format.right.style.should == 'solid'
414
- ## change top and right to dotted and observe
415
- @sheet2.cell('C8').format.top.style = 'dotted'
416
- @sheet2.cell('C8').format.right.style = 'dotted'
417
- @sheet2.cell('C8').format.bottom.style.should == 'solid'
418
- @sheet2.cell('C8').format.left.style.should == 'solid'
419
- @sheet2.cell('C8').format.top.style.should == 'dotted'
420
- @sheet2.cell('C8').format.right.style.should == 'dotted'
421
- end
422
- it 'deletes borders correctly', :pending=> 'consider how to deal with deleted borders' do
423
- @cell = @sheet1.cell(1,1)
424
-
425
- [@cell.format.top,@cell.format.left,@cell.format.right,@cell.format.bottom].each do |border|
426
- border.style = 'dashed'
427
- border.should_not be_nil
428
- border.delete
429
- border.should be_nil
430
- end
431
-
432
- # delete right border in existing file and observe
433
- @sheet2.cell('C8').format.right.delete
434
- @sheet2.cell('C8').format.right.should == nil
435
- end
436
-
437
- it 'can delete borders in many ways', :pending => 'consider what syntax to support' do
438
- @cell=@sheet2.cell('C8')
439
- @cell.border_right.should_not be_nil
440
- @cell.border_right.delete
441
- @cell.border_right.should be_nil
442
-
443
- @cell.border_left.should_not be_nil
444
- @cell.border_left = nil
445
- @cell.border_left.should be_nil
446
-
447
- @cell.format.top.should_not_be_nil
448
- @cell.format.top.style = 'none'
449
- @cell.border_top.should_not be_nil ## ?????
450
- end
451
-
452
- it 'automatically creates new style, if a style is automatic, some of its attributes changes and there are several cells pointing to it', :pending=>'' do
453
-
454
- end
455
333
 
456
334
  it 'gracefully accepts nil in assignement' do
457
335
  expect {
@@ -3,7 +3,7 @@ require 'bundler/setup'
3
3
  Bundler.setup
4
4
 
5
5
  RSpec.configure do |config|
6
- config.fail_fast = true
6
+ # config.fail_fast = 4
7
7
  # config.warnings = true
8
8
 
9
9
  # so i can run individual test just by appending :focus to them
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub A.Těšínský
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-24 00:00:00.000000000 Z
11
+ date: 2019-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -157,6 +157,7 @@ files:
157
157
  - lib/rspreadsheet/xml_tied_repeatable.rb
158
158
  - reinstall_local_gem.sh
159
159
  - rspreadsheet.gemspec
160
+ - spec/cell_format_spec.rb
160
161
  - spec/cell_spec.rb
161
162
  - spec/class_extensions_spec.rb
162
163
  - spec/column_spec.rb
@@ -169,6 +170,7 @@ files:
169
170
  - spec/spec_helper.rb.template
170
171
  - spec/test-image-blue.png
171
172
  - spec/test-image.png
173
+ - spec/testfile-issue-40.ods
172
174
  - spec/testfile1.ods
173
175
  - spec/testfile2-images.ods
174
176
  - spec/tools_spec.rb
@@ -201,6 +203,7 @@ specification_version: 4
201
203
  summary: Manipulating LibreOffice Calc (OpenDocument Spreadsheet) files from Ruby
202
204
  (read / create / modify).
203
205
  test_files:
206
+ - spec/cell_format_spec.rb
204
207
  - spec/cell_spec.rb
205
208
  - spec/class_extensions_spec.rb
206
209
  - spec/column_spec.rb
@@ -213,6 +216,7 @@ test_files:
213
216
  - spec/spec_helper.rb.template
214
217
  - spec/test-image-blue.png
215
218
  - spec/test-image.png
219
+ - spec/testfile-issue-40.ods
216
220
  - spec/testfile1.ods
217
221
  - spec/testfile2-images.ods
218
222
  - spec/tools_spec.rb