robust_excel_ole 1.4 → 1.5

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.
@@ -26,32 +26,28 @@ module RobustExcelOle
26
26
  # sheet name
27
27
  # @returns name of the sheet
28
28
  def name
29
- begin
30
- @ole_worksheet.Name
31
- rescue
32
- raise SheetREOError, "name #{name.inspect} could not be determined"
33
- end
29
+ @ole_worksheet.Name
30
+ rescue
31
+ raise SheetREOError, "name #{name.inspect} could not be determined"
34
32
  end
35
33
 
36
34
  # sets sheet name
37
- # @param [String] new_name the new name of the sheet
35
+ # @param [String] new_name the new name of the sheet
38
36
  def name= (new_name)
39
- begin
40
- @ole_worksheet.Name = new_name
41
- rescue WIN32OLERuntimeError => msg
42
- if msg.message =~ /800A03EC/
43
- raise NameAlreadyExists, "sheet name #{new_name.inspect} already exists"
44
- else
45
- raise UnexpectedREOError, "unexpected WIN32OLERuntimeError: #{msg.message}"
46
- end
37
+ @ole_worksheet.Name = new_name
38
+ rescue WIN32OLERuntimeError => msg
39
+ if msg.message =~ /800A03EC/
40
+ raise NameAlreadyExists, "sheet name #{new_name.inspect} already exists"
41
+ else
42
+ raise UnexpectedREOError, "unexpected WIN32OLERuntimeError: #{msg.message}"
47
43
  end
48
44
  end
49
45
 
50
46
  # a cell given the defined name or row and column
51
47
  # @params row, column, or name
52
- # @returns cell, if row and column are given
48
+ # @returns cell, if row and column are given
53
49
  def [] p1, p2 = :__not_provided
54
- if p2 != :__not_provided
50
+ if p2 != :__not_provided
55
51
  x, y = p1, p2
56
52
  xy = "#{x}_#{y}"
57
53
  @cells = { }
@@ -63,7 +59,7 @@ module RobustExcelOle
63
59
  else
64
60
  name = p1
65
61
  begin
66
- namevalue_glob(name)
62
+ namevalue_glob(name)
67
63
  rescue REOError
68
64
  namevalue(name)
69
65
  end
@@ -75,7 +71,7 @@ module RobustExcelOle
75
71
  def []= (p1, p2, p3 = :__not_provided)
76
72
  if p3 != :__not_provided
77
73
  x, y, value = p1, p2, p3
78
- set_cellval(x,y,value)
74
+ set_cellval(x,y,value)
79
75
  else
80
76
  name, value = p1, p2
81
77
  begin
@@ -106,31 +102,14 @@ module RobustExcelOle
106
102
 
107
103
  # sets the value of a cell, if row, column and color of the cell are given
108
104
  # @params [Integer] x,y row and column
109
- # @option opts [Symbol] :color the color of the cell when set
105
+ # @option opts [Symbol] :color the color of the cell when set
110
106
  def set_cellval(x,y,value, opts = {:color => 0})
111
- begin
112
- cell = @ole_worksheet.Cells.Item(x, y)
113
- cell.Interior.ColorIndex = opts[:color] # 42 - aqua-marin, 4-green
114
- @workbook.modified_cells << cell if @workbook
115
- cell.Value = value
116
- rescue WIN32OLERuntimeError
117
- raise RangeNotEvaluatable, "cannot assign value #{value.inspect} to cell (#{y.inspect},#{x.inspect})"
118
- end
119
- end
120
-
121
- # creates a range.
122
- # @params [Address] address
123
- # @return [Range] a range
124
- def range(address, address2 = :__not_provided)
125
- address = [address,address2] unless address2 == :__not_provided
126
- address = Address.new(address)
127
- begin
128
- RobustExcelOle::Range.new(@ole_worksheet.Range(
129
- @ole_worksheet.Cells(address.rows.min, address.columns.min),
130
- @ole_worksheet.Cells(address.rows.max, address.columns.max)))
131
- rescue WIN32OLERuntimeError
132
- raise RangeNotCreated, "cannot create range #{address.inspect}"
133
- end
107
+ cell = @ole_worksheet.Cells.Item(x, y)
108
+ cell.Interior.ColorIndex = opts[:color] # 42 - aqua-marin, 4-green
109
+ @workbook.modified_cells << cell if @workbook
110
+ cell.Value = value
111
+ rescue WIN32OLERuntimeError
112
+ raise RangeNotEvaluatable, "cannot assign value #{value.inspect} to cell (#{y.inspect},#{x.inspect})"
134
113
  end
135
114
 
136
115
  def each
@@ -144,9 +123,9 @@ module RobustExcelOle
144
123
  def each_with_index(offset = 0)
145
124
  i = offset
146
125
  each_row do |row_range|
147
- row_range.each do |cell|
126
+ row_range.each do |cell|
148
127
  yield cell, i
149
- i+=1
128
+ i += 1
150
129
  end
151
130
  end
152
131
  end
@@ -181,15 +160,14 @@ module RobustExcelOle
181
160
 
182
161
  def row_range(row, integer_range = nil)
183
162
  integer_range ||= 1..@end_column
184
- RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row , integer_range.min ), @ole_worksheet.Cells(row , integer_range.max )))
163
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(row, integer_range.min), @ole_worksheet.Cells(row, integer_range.max)))
185
164
  end
186
165
 
187
166
  def col_range(col, integer_range = nil)
188
167
  integer_range ||= 1..@end_row
189
- RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min , col ), @ole_worksheet.Cells(integer_range.max , col )))
168
+ RobustExcelOle::Range.new(@ole_worksheet.Range(@ole_worksheet.Cells(integer_range.min, col), @ole_worksheet.Cells(integer_range.max, col)))
190
169
  end
191
170
 
192
-
193
171
  def self.workbook_class # :nodoc: #
194
172
  @workbook_class ||= begin
195
173
  module_name = self.parent_name
@@ -204,28 +182,28 @@ module RobustExcelOle
204
182
  end
205
183
 
206
184
  def to_s # :nodoc: #
207
- "#<Worksheet: " + "#{"not alive " unless @workbook.alive?}" + "#{name}" + " #{File.basename(@workbook.stored_filename)} >"
185
+ '#<Worksheet: ' + ('not alive ' unless @workbook.alive?).to_s + name.to_s + " #{File.basename(@workbook.stored_filename)} >"
208
186
  end
209
187
 
210
188
  def inspect # :nodoc: #
211
189
  self.to_s
212
190
  end
213
191
 
214
- private
192
+ private
215
193
 
216
194
  def method_missing(name, *args) # :nodoc: #
217
- if name.to_s[0,1] =~ /[A-Z]/
195
+ if name.to_s[0,1] =~ /[A-Z]/
218
196
  begin
219
197
  @ole_worksheet.send(name, *args)
220
198
  rescue WIN32OLERuntimeError => msg
221
199
  if msg.message =~ /unknown property or method/
222
200
  raise VBAMethodMissingError, "unknown VBA property or method #{name.inspect}"
223
- else
201
+ else
224
202
  raise msg
225
203
  end
226
204
  end
227
- else
228
- super
205
+ else
206
+ super
229
207
  end
230
208
  end
231
209
 
@@ -241,13 +219,12 @@ module RobustExcelOle
241
219
  used_last_column = @ole_worksheet.UsedRange.Columns.Count
242
220
 
243
221
  special_last_column >= used_last_column ? special_last_column : used_last_column
244
- end
222
+ end
245
223
 
246
224
  end
247
225
 
248
- public
226
+ public
249
227
 
250
228
  Sheet = Worksheet
251
229
 
252
230
  end
253
-
@@ -1,10 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
- require "rspec"
2
+ require 'rspec'
3
3
  require 'tmpdir'
4
- require "fileutils"
4
+ require 'fileutils'
5
5
  require File.join(File.dirname(__FILE__), '../lib/robust_excel_ole')
6
6
 
7
- module RobustExcelOle::SpecHelpers # :nodoc: #
7
+ module RobustExcelOle::SpecHelpers # :nodoc: #
8
8
  def create_tmpdir # :nodoc: #
9
9
  tmpdir = Dir.mktmpdir
10
10
  FileUtils.cp_r(File.join(File.dirname(__FILE__), 'data'), tmpdir)
@@ -49,6 +49,24 @@ describe Workbook do
49
49
  end
50
50
  end
51
51
 
52
+ describe "Book" do
53
+
54
+ context "with standard options" do
55
+ before do
56
+ @book = Workbook.open(@simple_file)
57
+ end
58
+
59
+ after do
60
+ @book.close
61
+ end
62
+
63
+ it "should say that it lives" do
64
+ @book.should be_alive
65
+ end
66
+ end
67
+
68
+ end
69
+
52
70
  describe "Workbook::save" do
53
71
 
54
72
  it "should save a file, if it is open" do
@@ -1078,7 +1078,7 @@ describe Workbook do
1078
1078
  end
1079
1079
  end
1080
1080
 
1081
- context "name2range" do
1081
+ context "range" do
1082
1082
 
1083
1083
  before do
1084
1084
  @book1 = Workbook.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
@@ -1087,7 +1087,7 @@ describe Workbook do
1087
1087
 
1088
1088
  it "should create a range from the name" do
1089
1089
  @book1.add_name("foo",[1..3,1..4])
1090
- range = @book1.name2range("foo")
1090
+ range = @book1.range("foo")
1091
1091
  range.Address.should == "$A$1:$D$3"
1092
1092
  end
1093
1093
 
@@ -32,6 +32,24 @@ describe Worksheet do
32
32
  rm_tmp(@dir)
33
33
  end
34
34
 
35
+ describe "Sheet" do
36
+
37
+ describe 'access first and last sheet' do
38
+
39
+ it "should access the first sheet" do
40
+ first_sheet = @book.first_sheet
41
+ first_sheet.name.should == Sheet.new(@book.Sheets.Item(1)).Name
42
+ first_sheet.name.should == @book.sheet(1).Name
43
+ end
44
+
45
+ it "should access the last sheet" do
46
+ last_sheet = @book.last_sheet
47
+ last_sheet.name.should == Sheet.new(@book.Sheets.Item(3)).Name
48
+ last_sheet.name.should == @book.sheet(3).Name
49
+ end
50
+ end
51
+ end
52
+
35
53
  describe ".initialize" do
36
54
  context "when open sheet protected(with password is 'protect')" do
37
55
  before do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.4'
4
+ version: '1.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-06 00:00:00.000000000 Z
11
+ date: 2018-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec