robust_excel_ole 1.5 → 1.6

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
  SHA1:
3
- metadata.gz: 1d86cf14a83a7f64c9c81e1a5473a13e66ac8be2
4
- data.tar.gz: d7f78aba06eac6432722f36b4d753ed1b1cc94a7
3
+ metadata.gz: ba0c2ac25839e255753b710f0cf2d976742783f4
4
+ data.tar.gz: 21ed0ca20bf5ed9adce93c1c5530112be0ce4572
5
5
  SHA512:
6
- metadata.gz: 5c97c2fe5da0196f6021ad6a4bf1f62b1a1b7b1dd7c35df1699fd6f61894b5f1394ef8950cc2f1588775188a2909afe341400d1b7574c461b6990abb06c9ed4d
7
- data.tar.gz: e639929ed6031c0c4e041350a95d5b95aca527b956a917b4cad5ee578d301925599927d4c532dd80958a5306dce543fd4b27dbd2a0a6e36280484a3bd43ab23b
6
+ metadata.gz: eef30c124f4f9f6512617081f9c26bf8b6e82125bd9b6409d11aed50b96d5aa65c9a443c67233cc095f6062bfc53f6a709eb5b55f1c2b4c38a5e1e4408fe8a43
7
+ data.tar.gz: 533ce4e2e78f7a3ddcb248f998b0fa78e632bf29cbfb56c552c075f0dcd48797454be4c3a89b8f2d0eb48229718e14fa5532e4187f8121815215a80786862448
@@ -0,0 +1,74 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+ RubyInterpreters:
4
+ - ruby
5
+ - macruby
6
+ - rake
7
+ - jruby
8
+ - rbx
9
+ Include:
10
+ - '**/*.rb'
11
+ Exclude:
12
+ - doc/**/*
13
+ - docs/**/*
14
+ - examples/**/*
15
+ - rcov/**/*
16
+ - spec/**/*
17
+ - Changelog
18
+ - Guardfile
19
+ - Gemfile
20
+ - LICENSE
21
+ - Rakefile
22
+ - README.rdoc
23
+ - '**/*.bat'
24
+ - '**/*.gem'
25
+ - '**/*.md'
26
+ - '**/*.yml'
27
+ - '.gitignore/**/*'
28
+ - '.yardoc/**/*'
29
+ - '.yardopts/**/*'
30
+
31
+ Style/Encoding:
32
+ Enabled: false
33
+ Style/HashSyntax:
34
+ Enabled: false
35
+ Style/SymbolProc:
36
+ Enabled: false
37
+ Style/MethodDefParentheses:
38
+ Enabled: false
39
+ Style/RescueStandardError:
40
+ Enabled: false
41
+ Style/RescueModifier:
42
+ Enabled: false
43
+ Style/WordArray:
44
+ Enabled: false
45
+ Style/NumericLiterals:
46
+ Enabled: false
47
+ Style/RedundantSelf:
48
+ Enabled: false
49
+ Style/ParallelAssignment:
50
+ Enabled: false
51
+ Style/SymbolArray:
52
+ Enabled: false
53
+ Style/UnneededCondition:
54
+ Enabled: false
55
+ Style/BracesAroundHashParameters:
56
+ Enabled: false
57
+ Layout/SpaceAfterComma:
58
+ Enabled: false
59
+ Layout/EmptyLinesAroundModuleBody:
60
+ Enabled: false
61
+ Layout/EmptyLinesAroundClassBody:
62
+ Enabled: false
63
+ Layout/ExtraSpacing:
64
+ Enabled: false
65
+ Layout/EmptyLineAfterGuardClause:
66
+ Enabled: false
67
+ Layout/SpaceInsideHashLiteralBraces:
68
+ Enabled: false
69
+ Layout/SpaceAfterMethodName:
70
+ Enabled: false
71
+ Layout/AlignParameters:
72
+ Enabled: false
73
+ Layout/AccessModifierIndentation:
74
+ Enabled: false
data/Changelog CHANGED
@@ -1,6 +1,17 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.6]
5
+
6
+ ### Added
7
+ - Range#copy: options values_only, transpose
8
+
9
+ ## [1.5]
10
+
11
+ ### Changed
12
+ - Range,Cell#v
13
+ - Range,Cell: lower-letter VBA methods allowed
14
+
4
15
  ## [1.4.1]
5
16
 
6
17
  ### Changed
@@ -11,6 +22,7 @@ All notable changes to this project will be documented in this file.
11
22
  ### Changed
12
23
  - renamed Book to Workbook, Sheet to Worksheet
13
24
  - General#to_reo
25
+ - Range,Cell: lower-letter VBA methods not allowed
14
26
 
15
27
  ## [1.3.1]
16
28
 
@@ -45,23 +45,30 @@ or
45
45
  You can read the values by
46
46
 
47
47
  range.Value
48
+ => [["foo", "workbook", "sheet1", nil], ["foo", nil, "foobaaa", nil], ["matz", "is", "nice", nil]]
49
+
50
+ or
51
+
52
+ range.v
53
+ => [["foo", "workbook", "sheet1", nil], ["foo", nil, "foobaaa", nil], ["matz", "is", "nice", nil]]
48
54
 
49
55
  or as flat array
50
56
 
51
57
  range.values
58
+ => ["foo", "workbook", "sheet1", nil, "foo", nil, "foobaaa", nil, "matz", "is", "nice", nil]
52
59
 
53
- Now we copy and paste a range. With help of VBA methods you would do
60
+ Now we copy the range. With help of VBA methods you would do
54
61
 
55
- range.Copy(:destination => sheet.range([6,2]).ole_range)
62
+ range.Copy(:destination => sheet.range([4..6,5..8]).ole_range)
56
63
 
57
64
  or with help of RobustExcelOle
58
65
 
59
- range.copy([6,2])
66
+ range.copy([4,5])
60
67
 
61
68
  You can also copy a range into another worksheet in another workbook.
62
69
 
63
70
  book2 = Workbook.open('spec/data/another_workbook.xls', :excel => :new, :visible => true)
64
- range.copy([5,8],book2.sheet(3))
71
+ range.copy([4,5],book2.sheet(3))
65
72
 
66
73
  Now we define a name that refers to a range consisting of only the first cell, i.e. the 1st row and 1st column. Using VBA methods, you can use
67
74
 
@@ -112,6 +119,11 @@ or with RobustExcelOle
112
119
  sheet[1,1].Value
113
120
  => "foo
114
121
 
122
+ or
123
+
124
+ sheet[1,1].v
125
+ => "foo"
126
+
115
127
  Similarly, you can write a cell.
116
128
 
117
129
  sheet.Cells.Item(1,1).Value = "new_value"
@@ -156,14 +168,31 @@ You can access a range via its defined name with
156
168
 
157
169
  === Copying a range
158
170
 
159
- You can copy and paste a range.
171
+ Let's assume, you have a source range
160
172
 
161
- range.copy([6,2])
173
+ range = sheet.range(1..2,3..5)
162
174
 
163
- You can also copy a range into another worksheet in another workbook, and even another Excel instance. When copying into another Excel instance the destination shall be a cell (a rectangular range destination is not being considered)
175
+ or, in A1-format,
164
176
 
165
- book2 = Workbook.open('spec/data/another_workbook.xls', :excel => :new, :visible => true)
166
- range.copy([5,8],book2.sheet(3))
177
+ range = sheet.range("C1:E2")
178
+
179
+ To copy it to the destination range (3..4,6..8), you can use
180
+
181
+ range.copy([3..4,6..8])
182
+
183
+ or, providing the upper left position only,
184
+
185
+ range.copy([3,6])
186
+
187
+ You can copy the range into another worksheet of the same or another workbook, even in another Excel instance.
188
+
189
+ range.copy([3,6], destination_sheet)
190
+
191
+ Moreover, you can state, whether you want to copy the values only, and whether you want to transpose the destination range.
192
+
193
+ range.copy([3,6], destination_range, :values_only => true, :transpose => true)
194
+
195
+ Note that when you don't copy the values only but all formating as well, and you either copy into another Excel instance or transpose the range, the clipboard is being used.
167
196
 
168
197
  === Naming a cell
169
198
 
@@ -12,6 +12,10 @@ module RobustExcelOle
12
12
  end
13
13
  end
14
14
 
15
+ def v
16
+ self.Value
17
+ end
18
+
15
19
  def method_missing(name, *args) # :nodoc: #
16
20
  #if name.to_s[0,1] =~ /[A-Z]/
17
21
  begin
@@ -9,7 +9,10 @@ end
9
9
 
10
10
  module RobustExcelOle
11
11
 
12
- # see https://docs.microsoft.com/en-us/office/vba/api/excel.application(object)#methods
12
+ # This class essentially wraps a Win32Ole Application object.
13
+ # You can apply all VBA methods (starting with a capital letter)
14
+ # that you would apply for an Application object.
15
+ # See https://docs.microsoft.com/en-us/office/vba/api/excel.application(object)#methods
13
16
 
14
17
  class Excel < RangeOwners
15
18
  attr_accessor :ole_excel
@@ -244,6 +247,56 @@ module RobustExcelOle
244
247
  # :forget -> closes the excel instance without saving the workbooks
245
248
  # :alert -> give control to Excel
246
249
  # @option options [Proc] block
250
+ def self.close_all(options = { :if_unsaved => :raise }, &blk)
251
+ options[:if_unsaved] = blk if blk
252
+ finished_number = error_number = overall_number = 0
253
+ first_error = nil
254
+ finishing_action = proc do |excel|
255
+ if excel
256
+ begin
257
+ overall_number += 1
258
+ finished_number += excel.close(:if_unsaved => options[:if_unsaved])
259
+ rescue
260
+ first_error = $!
261
+ #trace "error when finishing #{$!}"
262
+ error_number += 1
263
+ end
264
+ end
265
+ end
266
+
267
+ # known Excel-instances
268
+ @@hwnd2excel.each do |hwnd, wr_excel|
269
+ if wr_excel.weakref_alive?
270
+ excel = wr_excel.__getobj__
271
+ if excel.alive?
272
+ excel.displayalerts = false
273
+ finishing_action.call(excel)
274
+ end
275
+ else
276
+ @@hwnd2excel.delete(hwnd)
277
+ end
278
+ end
279
+
280
+ # unknown Excel-instances
281
+ old_error_number = error_number
282
+ 9.times do |_index|
283
+ sleep 0.1
284
+ excel = begin
285
+ new(WIN32OLE.connect('Excel.Application'))
286
+ rescue
287
+ nil
288
+ end
289
+ finishing_action.call(excel) if excel
290
+ free_all_ole_objects unless (error_number > 0) && (options[:if_unsaved] == :raise)
291
+ break unless excel
292
+ break if error_number > old_error_number # + 3
293
+ end
294
+
295
+ raise first_error if ((options[:if_unsaved] == :raise) && first_error) || (first_error.class == OptionInvalid)
296
+
297
+ [finished_number, error_number]
298
+ end
299
+ =begin
247
300
  def self.close_all(options = { :if_unsaved => :raise }, &blk)
248
301
  options[:if_unsaved] = blk if blk
249
302
  finished_number = error_number = overall_number = 0
@@ -293,7 +346,7 @@ module RobustExcelOle
293
346
 
294
347
  [finished_number, error_number]
295
348
  end
296
-
349
+ =end
297
350
  # closes the Excel
298
351
  # @param [Hash] options the options
299
352
  # @option options [Symbol] :if_unsaved :raise, :save, :forget, :alert
@@ -1,6 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module RobustExcelOle
3
- # see https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet#methods
3
+
4
+ # This class essentially wraps a Win32Ole Range object.
5
+ # You can apply all VBA methods (starting with a capital letter)
6
+ # that you would apply for a Range object.
7
+ # See https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet#methods
4
8
 
5
9
  class Range < REOCommon
6
10
  include Enumerable
@@ -32,13 +36,138 @@ module RobustExcelOle
32
36
  end
33
37
  end
34
38
 
39
+ def v
40
+ self.Value
41
+ end
42
+
35
43
  def [] index
36
44
  @cells = []
37
45
  @cells[index + 1] = RobustExcelOle::Cell.new(@ole_range.Cells.Item(index + 1))
38
46
  end
39
47
 
40
48
  # copies a range
41
- # @params [Address] address of a range
49
+ # @params [Address or Address-Array] address or upper left position of the destination range
50
+ # @options [Worksheet] the destination worksheet
51
+ # @options [Hash] options: :transpose, :values_only
52
+ def copy(dest_address1, sheet_or_dest_address2 = :__not_provided, options_or_sheet = :__not_provided, not_provided_or_options = :__not_provided)
53
+ dest_address = if sheet_or_dest_address2.is_a?(Object::Range) or sheet_or_dest_address2.is_a?(Integer)
54
+ [dest_address1,sheet_or_dest_address2]
55
+ else
56
+ dest_address1
57
+ end
58
+ dest_sheet = if sheet_or_dest_address2.is_a?(Worksheet)
59
+ sheet_or_dest_address2
60
+ else
61
+ if options_or_sheet.is_a?(Worksheet)
62
+ options_or_sheet
63
+ else
64
+ @worksheet
65
+ end
66
+ end
67
+ options = if options_or_sheet.is_a?(Hash)
68
+ options_or_sheet
69
+ else
70
+ if not_provided_or_options.is_a?(Hash)
71
+ not_provided_or_options
72
+ else
73
+ { }
74
+ end
75
+ end
76
+ address = Address.new(dest_address)
77
+ dest_sheet = @worksheet if dest_sheet == :__not_provided
78
+ dest_address_is_position = (address.rows.min == address.rows.max && address.columns.min == address.columns.max)
79
+ dest_range_address = if (not dest_address_is_position)
80
+ [address.rows.min..address.rows.max,address.columns.min..address.columns.max]
81
+ else
82
+ if (not options[:transpose])
83
+ [address.rows.min..address.rows.min+self.Rows.Count-1,
84
+ address.columns.min..address.columns.min+self.Columns.Count-1]
85
+ else
86
+ [address.rows.min..address.rows.min+self.Columns.Count-1,
87
+ address.columns.min..address.columns.min+self.Rows.Count-1]
88
+ end
89
+ end
90
+ dest_range = dest_sheet.range(dest_range_address)
91
+ begin
92
+ if options[:values_only]
93
+ dest_range.Value = options[:transpose] ? self.Value.transpose : self.Value
94
+ else
95
+ if dest_range.worksheet.workbook.excel == @worksheet.workbook.excel
96
+ if options[:transpose]
97
+ self.Copy
98
+ dest_range.PasteSpecial(:transpose => true)
99
+ else
100
+ self.Copy(:destination => dest_range.ole_range)
101
+ end
102
+ else
103
+ if options[:transpose]
104
+ added_sheet = @worksheet.workbook.add_sheet
105
+ self.copy_special(dest_address, added_sheet, :transpose => true)
106
+ added_sheet.range(dest_range_address).copy_special(dest_address,dest_sheet)
107
+ @worksheet.workbook.excel.with_displayalerts(false) {added_sheet.Delete}
108
+ else
109
+ self.Copy
110
+ dest_sheet.Paste(:destination => dest_range.ole_range)
111
+ end
112
+ end
113
+ end
114
+ rescue WIN32OLERuntimeError
115
+ raise RangeNotCopied, 'cannot copy range'
116
+ end
117
+ end
118
+
119
+ # becomes copy
120
+ # copies a range
121
+ # @params [Address or Address-Array] address or upper left position of the destination range
122
+ # @options [Worksheet] the destination worksheet
123
+ # @options [Hash] options: :transpose, :values_only
124
+ def copy_special(dest_address, dest_sheet = :__not_provided, options = { })
125
+ address = Address.new(dest_address)
126
+ dest_sheet = @worksheet if dest_sheet == :__not_provided
127
+ dest_address_is_position = (address.rows.min == address.rows.max && address.columns.min == address.columns.max)
128
+ dest_range_address = if (not dest_address_is_position)
129
+ [address.rows.min..address.rows.max,address.columns.min..address.columns.max]
130
+ else
131
+ if (not options[:transpose])
132
+ [address.rows.min..address.rows.min+self.Rows.Count-1,
133
+ address.columns.min..address.columns.min+self.Columns.Count-1]
134
+ else
135
+ [address.rows.min..address.rows.min+self.Columns.Count-1,
136
+ address.columns.min..address.columns.min+self.Rows.Count-1]
137
+ end
138
+ end
139
+ dest_range = dest_sheet.range(dest_range_address)
140
+ begin
141
+ if options[:values_only]
142
+ dest_range.Value = options[:transpose] ? self.Value.transpose : self.Value
143
+ else
144
+ if dest_range.worksheet.workbook.excel == @worksheet.workbook.excel
145
+ if options[:transpose]
146
+ self.Copy
147
+ dest_range.PasteSpecial(:transpose => true)
148
+ else
149
+ self.Copy(:destination => dest_range.ole_range)
150
+ end
151
+ else
152
+ if options[:transpose]
153
+ added_sheet = @worksheet.workbook.add_sheet
154
+ self.copy_special(dest_address, added_sheet, :transpose => true)
155
+ added_sheet.range(dest_range_address).copy_special(dest_address,dest_sheet)
156
+ @worksheet.workbook.excel.with_displayalerts(false) {added_sheet.Delete}
157
+ else
158
+ self.Copy
159
+ dest_sheet.Paste(:destination => dest_range.ole_range)
160
+ end
161
+ end
162
+ end
163
+ rescue WIN32OLERuntimeError
164
+ raise RangeNotCopied, 'cannot copy range'
165
+ end
166
+ end
167
+
168
+ =begin
169
+ # copies a range
170
+ # @params [Address] address of the destination range
42
171
  # @options [Worksheet] the worksheet in which to copy
43
172
  def copy(address, sheet = :__not_provided, third_argument_deprecated = :__not_provided)
44
173
  if third_argument_deprecated != :__not_provided
@@ -56,11 +185,12 @@ module RobustExcelOle
56
185
  raise RangeNotCopied, 'cannot copy range'
57
186
  end
58
187
  else
59
- self.Select
188
+ #self.Select
60
189
  self.Copy
61
- sheet.Paste(destination_range)
190
+ sheet.Paste(:destination => destination_range)
62
191
  end
63
192
  end
193
+ =end
64
194
 
65
195
  def self.worksheet_class # :nodoc: #
66
196
  @worksheet_class ||= begin
@@ -171,7 +171,7 @@ module RobustExcelOle
171
171
  @rows = address_comp1.min.to_i..address_comp1.max.to_i
172
172
  if address_comp2.min.to_i == 0
173
173
  raise AddressInvalid, "address (#{address_comp1.inspect}, #{address_comp2.inspect}) not in A1-format" if address_comp1.min.to_i == 0
174
- @columns = str2num(address_comp2.min)..str2num(address_comp2.max)
174
+ @columns = str2num(address_comp2.begin)..str2num(address_comp2.end)
175
175
  else
176
176
  @columns = address_comp2.min.to_i..address_comp2.max.to_i
177
177
  end
@@ -330,9 +330,9 @@ module RobustExcelOle
330
330
  ))
331
331
  end
332
332
  rescue WIN32OLERuntimeError
333
- raise RangeNotCreated, "cannot create range (#{name_or_address.inspect},#{address2.inspect})"
334
- end
335
- raise RangeNotCreated, "cannot create range (#{name_or_address.inspect},#{address2.inspect})" if range.nil?
333
+ address2_string = address2.nil? ? "" : ", #{address2.inspect}"
334
+ raise RangeNotCreated, "cannot create range (#{name_or_address.inspect}#{address2_string})"
335
+ end
336
336
  range
337
337
  end
338
338
 
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.5"
2
+ VERSION = "1.6"
3
3
  end
@@ -4,7 +4,10 @@ require 'weakref'
4
4
 
5
5
  module RobustExcelOle
6
6
 
7
- # see https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods
7
+ # This class essentially wraps a Win32Ole Workbook object.
8
+ # You can apply all VBA methods (starting with a capital letter)
9
+ # that you would apply for a Workbook object.
10
+ # See https://docs.microsoft.com/en-us/office/vba/api/excel.workbook#methods
8
11
 
9
12
  class Workbook < RangeOwners
10
13
 
@@ -2,6 +2,9 @@
2
2
 
3
3
  module RobustExcelOle
4
4
 
5
+ # This class essentially wraps a Win32Ole Worksheet object.
6
+ # You can apply all VBA methods (starting with a capital letter)
7
+ # that you would apply for a Worksheet object.
5
8
  # see https://docs.microsoft.com/en-us/office/vba/api/excel.worksheet#methods
6
9
 
7
10
  class Worksheet < RangeOwners
Binary file
@@ -119,53 +119,175 @@ describe RobustExcelOle::Range do
119
119
  end
120
120
  end
121
121
 
122
+ describe "#v" do
123
+
124
+ context "v" do
125
+
126
+ it "should return value" do
127
+ @sheet[1,1].v.should == 'simple'
128
+ @sheet.range(1..2,3..4).v.should == [["sheet2", nil], [nil, nil]]
129
+ end
130
+ end
131
+
132
+ end
133
+
122
134
  describe "#copy" do
123
135
 
124
136
  before do
137
+ @book1 = Workbook.open(@dir + '/workbook.xls')
138
+ @sheet1 = @book1.sheet(1)
139
+ @range1 = @sheet1.range([1..2,1..3])
140
+ @sheet1[1,1].Interior.ColorIndex = 4
141
+ @book2 = Workbook.open(@dir + '/different_workbook.xls')
142
+ @sheet2 = @book2.sheet(2)
143
+ @book3 = Workbook.open(@dir + '/another_workbook.xls', :force => {:excel => :new})
144
+ @sheet3 = @book3.sheet(3)
145
+ end
146
+
147
+ after do
148
+ @book1.close(:if_unsaved => :forget)
149
+ @book2.close(:if_unsaved => :forget)
150
+ @book3.close(:if_unsaved => :forget)
151
+ end
152
+
153
+ it "should copy range" do
154
+ @range1.copy([4,2])
155
+ @sheet1.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
156
+ @sheet1[4,2].Interior.ColorIndex.should == 4
157
+ end
158
+
159
+ it "should copy range when giving an address" do
160
+ @range1.copy([4..5,2..4])
161
+ @sheet1.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
162
+ @sheet1[4,2].Interior.ColorIndex.should == 4
163
+ end
164
+
165
+ it "should copy range to another worksheet of another workbook" do
166
+ @range1.copy([4,2], @sheet2)
167
+ @sheet2.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
168
+ @sheet2[4,2].Interior.ColorIndex.should == 4
169
+ end
170
+
171
+ it "should copy range to another worksheet of another workbook of another Excel instance" do
172
+ @range1.copy([4,2], @sheet3)
173
+ @sheet3.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
174
+ @sheet3[4,2].Interior.ColorIndex.should == 4
175
+ end
176
+
177
+ it "should copy values only" do
178
+ @range1.copy([4,2], @sheet1, :values_only => true)
179
+ @sheet1.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
180
+ @sheet1[4,2].Interior.ColorIndex.should == -4142
181
+ end
182
+
183
+ it "should copy values only to another worksheet of another Excel instance" do
184
+ @range1.copy([4,2], @sheet3, :values_only => true)
185
+ @sheet3.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
186
+ @sheet3[4,2].Interior.ColorIndex.should == -4142
187
+ end
188
+
189
+ it "should copy and transpose with values only" do
190
+ @range1.copy([4,2], @sheet1, :values_only => true, :transpose => true)
191
+ @sheet1.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
192
+ @sheet1[4,2].Interior.ColorIndex.should == -4142
193
+ end
194
+
195
+ it "should copy and transpose with values only into another Excel instance" do
196
+ @range1.copy([4,2], @sheet3, :values_only => true, :transpose => true)
197
+ @sheet3.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
198
+ @sheet3[4,2].Interior.ColorIndex.should == -4142
199
+ end
200
+
201
+ it "should copy and transpose" do
202
+ @range1.copy([4,2], @sheet1, :transpose => true)
203
+ @sheet1.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
204
+ @sheet1[4,2].Interior.ColorIndex.should == 4
205
+ end
206
+
207
+ it "should copy and transpose into another Excel instance" do
208
+ @range1.copy([4,2], @sheet3, :transpose => true)
209
+ @sheet3.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
210
+ @sheet3[4,2].Interior.ColorIndex.should == 4
211
+ end
212
+ end
213
+
214
+ describe "#copy with deprecated interface" do
215
+
216
+ before do
217
+ @book1 = Workbook.open(@dir + '/workbook.xls')
218
+ @sheet1 = @book1.sheet(1)
219
+ @range1 = @sheet1.range([1..2,1..3])
220
+ @sheet1[1,1].Interior.ColorIndex = 4
125
221
  @book2 = Workbook.open(@dir + '/different_workbook.xls')
126
- @sheet2 = @book.sheet(1)
127
- @range2 = @sheet2.range([1..2,1..3])
222
+ @sheet2 = @book2.sheet(2)
128
223
  @book3 = Workbook.open(@dir + '/another_workbook.xls', :force => {:excel => :new})
224
+ @sheet3 = @book3.sheet(3)
129
225
  end
130
226
 
131
227
  after do
132
- @book.close(:if_unsaved => :forget)
228
+ @book1.close(:if_unsaved => :forget)
229
+ @book2.close(:if_unsaved => :forget)
230
+ @book3.close(:if_unsaved => :forget)
231
+ end
232
+
233
+ it "should copy range" do
234
+ @range1.copy(4,2)
235
+ @sheet1.range(4..5,2..4).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
236
+ @sheet1[4,2].Interior.ColorIndex.should == 4
237
+ end
238
+
239
+ it "should copy range when giving an address" do
240
+ @range1.copy(4..5,2..4)
241
+ @sheet1.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
242
+ @sheet1[4,2].Interior.ColorIndex.should == 4
243
+ end
244
+
245
+ it "should copy range to another worksheet of another workbook" do
246
+ @range1.copy(4,2, @sheet2)
247
+ @sheet2.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
248
+ @sheet2[4,2].Interior.ColorIndex.should == 4
249
+ end
250
+
251
+ it "should copy range to another worksheet of another workbook of another Excel instance" do
252
+ @range1.copy(4,2, @sheet3)
253
+ @sheet3.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
254
+ @sheet3[4,2].Interior.ColorIndex.should == 4
133
255
  end
134
256
 
135
- it "should copy range at a cell" do
136
- @range2.copy([4,4])
137
- @sheet2.range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
257
+ it "should copy values only" do
258
+ @range1.copy(4,2, @sheet1, :values_only => true)
259
+ @sheet1.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
260
+ @sheet1[4,2].Interior.ColorIndex.should == -4142
138
261
  end
139
262
 
140
- it "should copy range at a cell" do
141
- @range2.copy(["D4"])
142
- @sheet2.range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
263
+ it "should copy values only to another worksheet of another Excel instance" do
264
+ @range1.copy(4,2, @sheet3, :values_only => true)
265
+ @sheet3.range([4..5,2..4]).Value.should == [["foo", "workbook", "sheet1"],["foo", nil, "foobaaa"]]
266
+ @sheet3[4,2].Interior.ColorIndex.should == -4142
143
267
  end
144
268
 
145
- it "should copy range at a cell" do
146
- @range2.copy("D4")
147
- @sheet2.range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
269
+ it "should copy and transpose with values only" do
270
+ @range1.copy(4,2, @sheet1, :values_only => true, :transpose => true)
271
+ @sheet1.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
272
+ @sheet1[4,2].Interior.ColorIndex.should == -4142
148
273
  end
149
274
 
150
- it "should copy range into a certain worksheet of another workbook" do
151
- @range2.copy([4,4],@book2.sheet(3))
152
- @book2.sheet(3).range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
275
+ it "should copy and transpose with values only into another Excel instance" do
276
+ @range1.copy(4,2, @sheet3, :values_only => true, :transpose => true)
277
+ @sheet3.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
278
+ @sheet3[4,2].Interior.ColorIndex.should == -4142
153
279
  end
154
280
 
155
- it "should accept old interface" do
156
- @range2.copy(4,4,@book2.sheet(3))
157
- @book2.sheet(3).range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
281
+ it "should copy and transpose" do
282
+ @range1.copy(4,2, @sheet1, :transpose => true)
283
+ @sheet1.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
284
+ @sheet1[4,2].Interior.ColorIndex.should == 4
158
285
  end
159
286
 
160
- it "should copy range at a cell into a worksheet in another Excel instance" do
161
- Excel.kill_all
162
- sleep 1
163
- book1 = Workbook.open(@dir + '/workbook.xls', :force_excel => :new)
164
- book2 = Workbook.open(@dir + '/different_workbook.xls', :force_excel => :new)
165
- sheet1 = book1.sheet(1)
166
- range1 = sheet1.range([1..2,1..3])
167
- range1.copy([4,4],book2.sheet(1))
168
- book2.sheet(1).range([4..5,4..6]).values.should == ["foo", "workbook", "sheet1", "foo", nil, "foobaaa"]
287
+ it "should copy and transpose into another Excel instance" do
288
+ @range1.copy(4,2, @sheet3, :transpose => true)
289
+ @sheet3.range([4..6,2..3]).Value.should == [["foo", "foo"],["workbook", nil],["sheet1","foobaaa"]]
290
+ @sheet3[4,2].Interior.ColorIndex.should == 4
169
291
  end
170
292
 
171
293
  end
@@ -116,6 +116,12 @@ module RobustExcelOle
116
116
  address.columns == (1..2)
117
117
  end
118
118
 
119
+ it "should read a1-format for a rectangular range with several letters" do
120
+ address = Address.new(["S1:DP2"])
121
+ address.rows.should == (1..2)
122
+ address.columns.should == (19..120)
123
+ end
124
+
119
125
  it "should raise an error" do
120
126
  expect{
121
127
  Address.new("1A")
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.5'
4
+ version: '1.6'
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-19 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -39,6 +39,7 @@ extra_rdoc_files:
39
39
  - LICENSE
40
40
  files:
41
41
  - ".gitignore"
42
+ - ".rubocop.yml"
42
43
  - ".yardopts"
43
44
  - Changelog
44
45
  - Gemfile