robust_excel_ole 1.16 → 1.18.3

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +23 -0
  3. data/README.rdoc +17 -0
  4. data/benchmarking/Gemfile +7 -0
  5. data/benchmarking/README.md +131 -0
  6. data/benchmarking/creek_example.rb +33 -0
  7. data/benchmarking/generating_excel_files.rb +28 -0
  8. data/benchmarking/reo_example.rb +26 -0
  9. data/benchmarking/reo_example1.rb +31 -0
  10. data/benchmarking/reo_example2.rb +26 -0
  11. data/benchmarking/roo_example.rb +33 -0
  12. data/benchmarking/ruby_xl_example.rb +36 -0
  13. data/benchmarking/sample_excel_files/xlsx_500_rows.xlsx +0 -0
  14. data/benchmarking/simple_xlsx_reader_example.rb +33 -0
  15. data/benchmarking/spreadsheet_example.rb +36 -0
  16. data/bin/jreo.bat +3 -0
  17. data/bin/reo.bat +3 -0
  18. data/docs/README_excel.rdoc +6 -0
  19. data/docs/README_open.rdoc +4 -0
  20. data/docs/README_ranges.rdoc +15 -0
  21. data/examples/example_ruby_library.rb +27 -0
  22. data/lib/robust_excel_ole.rb +4 -3
  23. data/lib/robust_excel_ole/{address.rb → address_tool.rb} +23 -22
  24. data/lib/robust_excel_ole/{reo_common.rb → base.rb} +2 -90
  25. data/lib/robust_excel_ole/bookstore.rb +2 -2
  26. data/lib/robust_excel_ole/cell.rb +30 -18
  27. data/lib/robust_excel_ole/excel.rb +65 -30
  28. data/lib/robust_excel_ole/general.rb +7 -5
  29. data/lib/robust_excel_ole/range.rb +38 -15
  30. data/lib/robust_excel_ole/range_owners.rb +26 -11
  31. data/lib/robust_excel_ole/vba_objects.rb +30 -0
  32. data/lib/robust_excel_ole/version.rb +1 -1
  33. data/lib/robust_excel_ole/workbook.rb +136 -147
  34. data/lib/robust_excel_ole/worksheet.rb +47 -15
  35. data/lib/rubygems_plugin.rb +3 -0
  36. data/robust_excel_ole.gemspec +1 -1
  37. data/spec/address_tool_spec.rb +175 -0
  38. data/spec/{reo_common_spec.rb → base_spec.rb} +10 -29
  39. data/spec/cell_spec.rb +67 -25
  40. data/spec/data/more_data/workbook.xls +0 -0
  41. data/spec/excel_spec.rb +41 -273
  42. data/spec/general_spec.rb +15 -19
  43. data/spec/range_spec.rb +57 -3
  44. data/spec/workbook_spec.rb +7 -75
  45. data/spec/workbook_specs/workbook_misc_spec.rb +10 -10
  46. data/spec/workbook_specs/workbook_open_spec.rb +228 -14
  47. data/spec/workbook_specs/workbook_unobtr_spec.rb +31 -31
  48. data/spec/worksheet_spec.rb +42 -0
  49. metadata +27 -8
  50. data/spec/address_spec.rb +0 -174
@@ -12,7 +12,7 @@ module RobustExcelOle
12
12
  class Worksheet < RangeOwners
13
13
 
14
14
  attr_reader :ole_worksheet
15
- #attr_reader :workbook
15
+ attr_reader :workbook
16
16
 
17
17
  def initialize(win32_worksheet)
18
18
  @ole_worksheet = win32_worksheet
@@ -28,17 +28,18 @@ module RobustExcelOle
28
28
  end
29
29
 
30
30
  def workbook
31
- return @workbook unless @workbook.nil?
32
- begin
31
+ @workbook ||= begin
33
32
  ole_workbook = self.Parent
34
33
  saved_status = ole_workbook.Saved
35
34
  ole_workbook.Saved = true unless saved_status
36
35
  @workbook = workbook_class.new(ole_workbook)
37
36
  ole_workbook.Saved = saved_status
38
- rescue
39
- nil
37
+ @workbook
40
38
  end
41
- @workbook
39
+ end
40
+
41
+ def excel
42
+ workbook.excel
42
43
  end
43
44
 
44
45
  # sheet name
@@ -70,7 +71,7 @@ module RobustExcelOle
70
71
  xy = "#{x}_#{y}"
71
72
  @cells = { }
72
73
  begin
73
- @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y))
74
+ @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y), @worksheet)
74
75
  rescue
75
76
  raise RangeNotEvaluatable, "cannot read cell (#{x.inspect},#{y.inspect})"
76
77
  end
@@ -107,16 +108,26 @@ module RobustExcelOle
107
108
  # value of a cell, if row and column are given
108
109
  # @params row and column
109
110
  # @returns value of the cell
111
+ def cellval(x,y)
112
+ begin
113
+ @ole_worksheet.Cells.Item(x, y).Value
114
+ rescue
115
+ raise RangeNotEvaluatable, "cannot read cell (#{x.inspect},#{y.inspect})"
116
+ end
117
+ end
118
+
119
+ =begin
110
120
  def cellval(x,y)
111
121
  xy = "#{x}_#{y}"
112
122
  @cells = { }
113
123
  begin
114
- @cells[xy] = RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y))
124
+ @cells[xy] ||= RobustExcelOle::Cell.new(@ole_worksheet.Cells.Item(x, y), @worksheet)
115
125
  @cells[xy].Value
116
126
  rescue
117
127
  raise RangeNotEvaluatable, "cannot read cell (#{p1.inspect},#{p2.inspect})"
118
128
  end
119
129
  end
130
+ =end
120
131
 
121
132
  # sets the value of a cell, if row, column and color of the cell are given
122
133
  # @params [Integer] x,y row and column
@@ -129,6 +140,10 @@ module RobustExcelOle
129
140
  raise RangeNotEvaluatable, "cannot assign value #{value.inspect} to cell (#{y.inspect},#{x.inspect})"
130
141
  end
131
142
 
143
+ def values
144
+ @ole_worksheet.UsedRange.Value
145
+ end
146
+
132
147
  def each
133
148
  each_row do |row_range|
134
149
  row_range.each do |cell|
@@ -147,17 +162,35 @@ module RobustExcelOle
147
162
  end
148
163
  end
149
164
 
165
+ def each_rowvalue
166
+ @ole_worksheet.UsedRange.Value.each do |row_values|
167
+ yield row_values
168
+ end
169
+ end
170
+
171
+ def each_value # :deprecated: #
172
+ each_rowvalue
173
+ end
174
+
175
+ def each_rowvalue_with_index(offset = 0)
176
+ i = offset
177
+ @ole_worksheet.UsedRange.Value.each do |row_values|
178
+ yield row_values, i
179
+ i += 1
180
+ end
181
+ end
182
+
150
183
  def each_row(offset = 0)
151
184
  offset += 1
152
185
  1.upto(@end_row) do |row|
153
186
  next if row < offset
154
- yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, 1), @ole_worksheet.Cells(row, @end_column)))
187
+ yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, 1), @ole_worksheet.Cells(row, @end_column)), self)
155
188
  end
156
189
  end
157
190
 
158
191
  def each_row_with_index(offset = 0)
159
192
  each_row(offset) do |row_range|
160
- yield RobustExcelOle::Range.new(row_range), (row_range.Row - 1 - offset)
193
+ yield RobustExcelOle::Range.new(row_range, self), (row_range.Row - 1 - offset)
161
194
  end
162
195
  end
163
196
 
@@ -165,24 +198,24 @@ module RobustExcelOle
165
198
  offset += 1
166
199
  1.upto(@end_column) do |column|
167
200
  next if column < offset
168
- yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(1, column), @ole_worksheet.Cells(@end_row, column)))
201
+ yield RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(1, column), @ole_worksheet.Cells(@end_row, column)), self)
169
202
  end
170
203
  end
171
204
 
172
205
  def each_column_with_index(offset = 0)
173
206
  each_column(offset) do |column_range|
174
- yield RobustExcelOle::Range.new(column_range), (column_range.Column - 1 - offset)
207
+ yield RobustExcelOle::Range.new(column_range, self), (column_range.Column - 1 - offset)
175
208
  end
176
209
  end
177
210
 
178
211
  def row_range(row, integer_range = nil)
179
212
  integer_range ||= 1..@end_column
180
- RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, integer_range.min), @ole_worksheet.Cells(row, integer_range.max)))
213
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, integer_range.min), @ole_worksheet.Cells(row, integer_range.max)), self)
181
214
  end
182
215
 
183
216
  def col_range(col, integer_range = nil)
184
217
  integer_range ||= 1..@end_row
185
- RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)))
218
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)), self)
186
219
  end
187
220
 
188
221
  def == other_worksheet
@@ -218,7 +251,6 @@ module RobustExcelOle
218
251
 
219
252
  private
220
253
 
221
- # @private
222
254
  def method_missing(name, *args)
223
255
  if name.to_s[0,1] =~ /[A-Z]/
224
256
  if ::ERRORMESSAGE_JRUBY_BUG
@@ -0,0 +1,3 @@
1
+ Gem.post_install do
2
+ puts "post_install called for gem"
3
+ end
@@ -34,5 +34,5 @@ Gem::Specification.new do |s|
34
34
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
35
35
  s.require_paths = ["lib"]
36
36
  s.add_development_dependency "rspec", '>= 2.6.0'
37
- s.required_ruby_version = '>= 1.8.6'
37
+ s.required_ruby_version = '>= 2.1'
38
38
  end
@@ -0,0 +1,175 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), './spec_helper')
4
+ require File.expand_path( '../../lib/robust_excel_ole/base', __FILE__)
5
+
6
+ $VERBOSE = nil
7
+
8
+ include General
9
+ include RobustExcelOle
10
+
11
+ module RobustExcelOle
12
+
13
+ describe AddressTool do
14
+
15
+ before(:all) do
16
+ excel = Excel.new(:reuse => true)
17
+ open_books = excel == nil ? 0 : excel.Workbooks.Count
18
+ puts "*** open books *** : #{open_books}" if open_books > 0
19
+ Excel.kill_all
20
+ @dir = create_tmpdir
21
+ @simple_file = @dir + '/workbook.xls'
22
+ @workbook = Workbook.open(@simple_file)
23
+ @address_tool = @workbook.excel.address_tool
24
+ end
25
+
26
+ after(:all) do
27
+ @workbook.close
28
+ end
29
+
30
+ it "should transform relative r1c1-reference into r1c1-format" do
31
+ @address_tool.as_r1c1("Z1S[2]:Z[-1]S4").should == "Z1S(2):Z(-1)S4"
32
+ @address_tool.as_r1c1("Z[1]S2:Z3S[4]").should == "Z(1)S2:Z3S(4)"
33
+ @address_tool.as_r1c1("Z1S[2]").should == "Z1S(2)"
34
+ @address_tool.as_r1c1("Z[-1]S4").should == "Z(-1)S4"
35
+ @address_tool.as_r1c1("Z[3]").should == "Z(3)"
36
+ @address_tool.as_r1c1("S[-2]").should == "S(-2)"
37
+ end
38
+
39
+ # test for 1.8.6
40
+ it "should transform relative integer_ranges-format into r1c1-format" do
41
+ @address_tool.as_r1c1([1..2,[3]..4]).should == "Z1S(3):Z2S4"
42
+ @address_tool.as_r1c1([[1]..2,3..4]).should == "Z(1)S3:Z2S4"
43
+ @address_tool.as_r1c1([[1]..2,nil]).should == "Z(1):Z2"
44
+ @address_tool.as_r1c1([nil,[1]..2]).should == "S(1):S2"
45
+ @address_tool.as_r1c1([nil,[1]]).should == "S(1):S(1)"
46
+ end
47
+
48
+ it "should transform relative integer_ranges-format into r1c1-format" do
49
+ @address_tool.as_r1c1([1..[-2],[3]..4]).should == "Z1S(3):Z(-2)S4"
50
+ @address_tool.as_r1c1([[1]..2,3..[4]]).should == "Z(1)S3:Z2S(4)"
51
+ @address_tool.as_r1c1([1..[-2],nil]).should == "Z1:Z(-2)"
52
+ @address_tool.as_r1c1([nil,[-1]..2]).should == "S(-1):S2"
53
+ @address_tool.as_r1c1([[3]..[3],nil]).should == "Z(3):Z(3)"
54
+ @address_tool.as_r1c1([nil,[-2]..[-2]]).should == "S(-2):S(-2)"
55
+ @address_tool.as_r1c1([[3],nil]).should == "Z(3):Z(3)"
56
+ end
57
+
58
+ it "should transform relative r1c1-format into r1c1-format" do
59
+ @address_tool.as_integer_ranges("Z1S[2]:Z[3]S4").should == [1..[3],[2]..4]
60
+ @address_tool.as_integer_ranges("Z[1]S2:Z3S[4]").should == [[1]..3,2..[4]]
61
+ @address_tool.as_integer_ranges("Z1S[2]").should == [1..1,[2]..[2]]
62
+ @address_tool.as_integer_ranges("Z[3]S4").should == [[3]..[3],4..4]
63
+ end
64
+
65
+ it "should transform a1-format" do
66
+ @address_tool.as_a1("A2").should == "A2"
67
+ @address_tool.as_r1c1("A2").should == "Z2S1:Z2S1"
68
+ @address_tool.as_integer_ranges("A2").should == [2..2,1..1]
69
+ end
70
+
71
+ it "should transform several-letter-a1-format" do
72
+ @address_tool.as_a1("ABO15").should == "ABO15"
73
+ @address_tool.as_r1c1("ABO15").should == "Z15S743:Z15S743"
74
+ @address_tool.as_integer_ranges("ABO15").should == [15..15,743..743]
75
+ end
76
+
77
+ it "should transform complex a1-format" do
78
+ @address_tool.as_a1("A2:B3").should == "A2:B3"
79
+ @address_tool.as_r1c1("A2:B3").should == "Z2S1:Z3S2"
80
+ @address_tool.as_integer_ranges("A2:B3").should == [2..3,1..2]
81
+ @address_tool.as_a1("S1:DP2").should == "S1:DP2"
82
+ @address_tool.as_r1c1("S1:DP2").should == "Z1S19:Z2S120"
83
+ @address_tool.as_integer_ranges("S1:DP2").should == [1..2,19..120]
84
+ end
85
+
86
+ it "should transform infinite a1-format" do
87
+ @address_tool.as_a1("A:B").should == "A:B"
88
+ @address_tool.as_r1c1("A:B").should == "S1:S2"
89
+ @address_tool.as_integer_ranges("A:B").should == [nil,1..2]
90
+ @address_tool.as_a1("1:3").should == "1:3"
91
+ @address_tool.as_r1c1("1:3").should == "Z1:Z3"
92
+ @address_tool.as_integer_ranges("1:3").should == [1..3,nil]
93
+ @address_tool.as_a1("B").should == "B"
94
+ @address_tool.as_r1c1("B").should == "S2:S2"
95
+ @address_tool.as_integer_ranges("B").should == [nil,2..2]
96
+ @address_tool.as_a1("3").should == "3"
97
+ @address_tool.as_r1c1("3").should == "Z3:Z3"
98
+ @address_tool.as_integer_ranges("3").should == [3..3,nil]
99
+ end
100
+
101
+ it "should transform r1c1-format" do
102
+ @address_tool.as_r1c1("Z2S1").should == "Z2S1"
103
+ @address_tool.as_integer_ranges("Z2S1").should == [2..2,1..1]
104
+ expect{
105
+ @address_tool.as_a1("Z2S1")
106
+ }.to raise_error(NotImplementedREOError)
107
+ end
108
+
109
+ it "should transform complex r1c1-format" do
110
+ @address_tool.as_r1c1("Z2S1:Z3S2").should == "Z2S1:Z3S2"
111
+ @address_tool.as_integer_ranges("Z2S1:Z3S2").should == [2..3,1..2]
112
+ end
113
+
114
+ it "should transform as_integer_ranges format" do
115
+ @address_tool.as_integer_ranges([2..2,1..1]).should == [2..2,1..1]
116
+ @address_tool.as_r1c1([2..2,1..1]).should == "Z2S1:Z2S1"
117
+ expect{
118
+ @address_tool.as_a1([2..2,1..1])
119
+ }.to raise_error(NotImplementedREOError)
120
+ end
121
+
122
+ it "should transform simple as_integer_ranges format" do
123
+ @address_tool.as_integer_ranges([2,1]).should == [2..2,1..1]
124
+ @address_tool.as_r1c1([2,1]).should == "Z2S1:Z2S1"
125
+ end
126
+
127
+ it "should transform complex as_integer_ranges format" do
128
+ @address_tool.as_integer_ranges([2,"A"]).should == [2..2,1..1]
129
+ @address_tool.as_r1c1([2,"A"]).should == "Z2S1:Z2S1"
130
+ @address_tool.as_integer_ranges([2,"A".."B"]).should == [2..2,1..2]
131
+ @address_tool.as_r1c1([2,"A".."B"]).should == "Z2S1:Z2S2"
132
+ @address_tool.as_integer_ranges([1..2,"C"]).should == [1..2,3..3]
133
+ @address_tool.as_r1c1([1..2,"C"]).should == "Z1S3:Z2S3"
134
+ @address_tool.as_integer_ranges([1..2,"C".."E"]).should == [1..2,3..5]
135
+ @address_tool.as_r1c1([1..2,"C".."E"]).should == "Z1S3:Z2S5"
136
+ @address_tool.as_integer_ranges([2,3..5]).should == [2..2,3..5]
137
+ @address_tool.as_r1c1([2,3..5]).should == "Z2S3:Z2S5"
138
+ @address_tool.as_integer_ranges([1..2,3..5]).should == [1..2,3..5]
139
+ @address_tool.as_r1c1([1..2,3..5]).should == "Z1S3:Z2S5"
140
+ end
141
+
142
+ it "should transform infinite as_integer_ranges format" do
143
+ @address_tool.as_integer_ranges([nil,1..2]).should == [nil,1..2]
144
+ @address_tool.as_r1c1([nil,1..2]).should == "S1:S2"
145
+ @address_tool.as_integer_ranges([1..3,nil]).should == [1..3,nil]
146
+ @address_tool.as_r1c1([1..3,nil]).should == "Z1:Z3"
147
+ @address_tool.as_integer_ranges([nil,2]).should == [nil,2..2]
148
+ @address_tool.as_r1c1([nil,2]).should == "S2:S2"
149
+ @address_tool.as_integer_ranges([3,nil]).should == [3..3,nil]
150
+ @address_tool.as_r1c1([3,nil]).should == "Z3:Z3"
151
+ end
152
+
153
+ it "should raise an error" do
154
+ expect{
155
+ @address_tool.as_a1("1A")
156
+ }.to raise_error(AddressInvalid, /format not correct/)
157
+ expect{
158
+ @address_tool.as_r1c1("A1B")
159
+ }.to raise_error(AddressInvalid, /format not correct/)
160
+ #expect{
161
+ # @address_tool.as_integer_ranges(["A".."B","C".."D"])
162
+ #}.to raise_error(AddressInvalid, /format not correct/)
163
+ #expect{
164
+ # @address_tool.as_integer_ranges(["A".."B",1..2])
165
+ #}.to raise_error(AddressInvalid, /format not correct/)
166
+ #expect{
167
+ # @address_tool.as_integer_ranges(["A".."B",nil])
168
+ #}.to raise_error(AddressInvalid, /format not correct/)
169
+ expect{
170
+ @address_tool.as_integer_ranges(["A",1,2])
171
+ }.to raise_error(AddressInvalid, /more than two components/)
172
+ end
173
+
174
+ end
175
+ end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require File.join(File.dirname(__FILE__), './spec_helper')
4
- require File.expand_path( '../../lib/robust_excel_ole/reo_common', __FILE__)
4
+ require File.expand_path( '../../lib/robust_excel_ole/base', __FILE__)
5
5
 
6
6
  $VERBOSE = nil
7
7
 
@@ -10,7 +10,7 @@ include RobustExcelOle
10
10
 
11
11
  module RobustExcelOle
12
12
 
13
- describe REOCommon do
13
+ describe Base do
14
14
 
15
15
  before(:all) do
16
16
  excel = Excel.new(:reuse => true)
@@ -40,12 +40,12 @@ module RobustExcelOle
40
40
 
41
41
  it "should put some number" do
42
42
  a = 4
43
- REOCommon::trace "some text #{a}"
43
+ Base::trace "some text #{a}"
44
44
  end
45
45
 
46
46
  it "should put another text" do
47
47
  b = Workbook.open(@simple_file)
48
- REOCommon::trace "book: #{b}"
48
+ Base::trace "book: #{b}"
49
49
  end
50
50
  end
51
51
 
@@ -82,45 +82,26 @@ module RobustExcelOle
82
82
 
83
83
  end
84
84
 
85
- describe "Object methods" do
86
-
87
- before do
88
- @book = Workbook.open(@simple_file)
89
- @sheet = @book.sheet(1)
90
- end
91
-
92
- before do
93
- @book.close
94
- end
95
-
96
- it "should raise an error when asking excel of a sheet" do
97
- expect{
98
- @sheet.excel
99
- }.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a Workbook")
100
- end
101
-
102
- end
103
-
104
85
  describe "misc" do
105
86
 
106
87
  it "should" do
107
88
 
108
89
  LOG_TO_STDOUT = true
109
- REOCommon::trace "foo"
90
+ Base::trace "foo"
110
91
 
111
92
  LOG_TO_STDOUT = false
112
- REOCommon::trace "foo"
93
+ Base::trace "foo"
113
94
 
114
95
  REO_LOG_DIR = ""
115
- REOCommon::trace "foo"
96
+ Base::trace "foo"
116
97
 
117
98
  #REO_LOG_DIR = "C:"
118
- #REOCommon::trace "foo"
99
+ #Base::trace "foo"
119
100
 
120
- REOCommon::tr1 "foo"
101
+ Base::tr1 "foo"
121
102
 
122
103
  h = {:a => {:c => 4}, :b => 2}
123
- REOCommon::puts_hash(h)
104
+ Base::puts_hash(h)
124
105
 
125
106
  end
126
107
 
@@ -15,54 +15,66 @@ describe Cell do
15
15
 
16
16
  before do
17
17
  @dir = create_tmpdir
18
+ @simple_file = @dir + '/workbook.xls'
19
+ @merge_cells_file = @dir + '/merge_cells.xls'
20
+ @book = Workbook.open(@simple_file)
21
+ @sheet = @book.sheet(1)
22
+ @cell = @sheet[1, 1]
18
23
  end
19
24
 
20
25
  after do
26
+ Excel.kill_all
21
27
  rm_tmp(@dir)
22
28
  end
23
29
 
24
- context "open simple.xls" do
25
- before do
26
- @book = Workbook.open(@dir + '/workbook.xls', :read_only => true)
27
- @sheet = @book.sheet(2)
28
- @cell = @sheet[1, 1]
30
+
31
+ describe "values" do
32
+
33
+ it "should yield one element values" do
34
+ @cell.values.should == ["foo"]
29
35
  end
30
36
 
31
- after do
32
- @book.close
37
+ end
38
+
39
+ describe "#[]" do
40
+
41
+ it "should access to the cell itself" do
42
+ @cell[0].should be_kind_of RobustExcelOle::Cell
43
+ @cell[0].v.should == "foo"
33
44
  end
34
45
 
35
- describe "#value" do
36
- it "get cell's value" do
37
- @cell.Value.should eq 'simple'
38
- end
46
+ it "should access to the cell itself" do
47
+ @cell[1].should be_kind_of RobustExcelOle::Cell
48
+ @cell[1].v.should == 'foo'
39
49
  end
50
+
51
+ end
40
52
 
41
- describe "#value=" do
42
- it "change cell data to 'fooooo'" do
43
- @cell.Value = 'fooooo'
44
- @cell.Value.should eq 'fooooo'
45
- end
53
+ describe "#copy" do
54
+
55
+ before do
56
+ @book1 = Workbook.open(@dir + '/workbook.xls')
57
+ @sheet1 = @book1.sheet(1)
58
+ @cell1 = @sheet1[1,1]
46
59
  end
47
60
 
48
- describe "#method_missing" do
49
- context "unknown method" do
50
- it { expect { @cell.hogehogefoo }.to raise_error }
51
- end
61
+ after do
62
+ @book1.close(:if_unsaved => :forget)
52
63
  end
53
64
 
65
+ it "should copy range" do
66
+ @cell1.copy([2,3])
67
+ @sheet1.range([1..2,1..3]).v.should == [["foo", "workbook", "sheet1"],["foo", nil, "foo"]]
68
+ end
54
69
  end
55
70
 
56
71
  context "open merge_cells.xls" do
72
+
57
73
  before do
58
- @book = Workbook.open(@dir + '/merge_cells.xls', :read_only => true)
74
+ @book = Workbook.open(@merge_cells_file, :read_only => true)
59
75
  @sheet = @book.sheet(1)
60
76
  end
61
77
 
62
- after do
63
- @book.close
64
- end
65
-
66
78
  it "merged cell get same value" do
67
79
  @sheet[1, 1].Value.should be_nil
68
80
  @sheet[2, 1].Value.should eq 'first merged'
@@ -74,4 +86,34 @@ describe Cell do
74
86
  @sheet[2, 2].Value.should eq "set merge cell"
75
87
  end
76
88
  end
89
+
90
+ describe "==" do
91
+
92
+ it "should check equality of cells" do
93
+ @cell.should == @sheet[1,1]
94
+ @cell.should_not == @sheet[1,2]
95
+ end
96
+
97
+ end
98
+
99
+ describe "#Value" do
100
+ it "get cell's value" do
101
+ @cell.Value.should eq 'foo'
102
+ end
103
+ end
104
+
105
+ describe "#Value=" do
106
+ it "change cell data to 'fooooo'" do
107
+ @cell.Value = 'fooooo'
108
+ @cell.Value.should eq 'fooooo'
109
+ end
110
+ end
111
+
112
+ describe "#method_missing" do
113
+ context "unknown method" do
114
+ it { expect { @cell.hogehogefoo }.to raise_error(NoMethodError) }
115
+ end
116
+ end
117
+
77
118
  end
119
+