robust_excel_ole 1.30 → 1.31
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.
- checksums.yaml +4 -4
- data/Changelog +5 -0
- data/README.rdoc +4 -2
- data/benchmarking/reo_example.rb +1 -1
- data/benchmarking/reo_example1.rb +1 -1
- data/benchmarking/reo_example2.rb +1 -1
- data/docs/README_sheet.rdoc +1 -7
- data/examples/introductory_examples/example_open.rb +11 -0
- data/lib/robust_excel_ole.rb +18 -14
- data/lib/robust_excel_ole/cell.rb +1 -1
- data/lib/robust_excel_ole/cygwin.rb +2 -0
- data/lib/robust_excel_ole/general.rb +30 -80
- data/lib/robust_excel_ole/list_object.rb +17 -118
- data/lib/robust_excel_ole/list_row.rb +128 -0
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +47 -14
- data/lib/robust_excel_ole/worksheet.rb +35 -18
- data/lib/spec_helper.rb +1 -1
- data/spec/address_tool_spec.rb +2 -2
- data/spec/base_spec.rb +2 -2
- data/spec/bookstore_spec.rb +1 -1
- data/spec/cell_spec.rb +1 -1
- data/spec/cygwin_spec.rb +1 -1
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +1 -1
- data/spec/general_spec.rb +34 -7
- data/spec/list_object_spec.rb +85 -20
- data/spec/range_spec.rb +1 -14
- data/spec/spec_helper.rb +1 -1
- data/spec/workbook_spec.rb +1 -1
- data/spec/workbook_specs/workbook_all_spec.rb +8 -28
- data/spec/workbook_specs/workbook_close_spec.rb +1 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +3 -3
- data/spec/workbook_specs/workbook_open_spec.rb +45 -5
- data/spec/workbook_specs/workbook_save_spec.rb +1 -1
- data/spec/workbook_specs/workbook_sheet_spec.rb +1 -1
- data/spec/workbook_specs/workbook_subclass_spec.rb +1 -1
- data/spec/workbook_specs/workbook_unobtr_spec.rb +40 -62
- data/spec/worksheet_spec.rb +33 -1
- metadata +3 -2
data/spec/list_object_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'spec_helper'
|
4
4
|
|
5
5
|
$VERBOSE = nil
|
6
6
|
|
@@ -107,28 +107,93 @@ describe ListObject do
|
|
107
107
|
|
108
108
|
describe "getting and setting values" do
|
109
109
|
|
110
|
-
context "with
|
110
|
+
context "with various column names" do
|
111
|
+
|
112
|
+
context "with standard" do
|
113
|
+
|
114
|
+
before do
|
115
|
+
@table = Table.new(@sheet, "table_name", [12,1], 3, ["Person1","Win/Sales", "xiq-Xs", "OrderID", "YEAR", "length in m", "Amo%untSal___es"])
|
116
|
+
@table_row1 = @table[1]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should read and set values via alternative column names" do
|
120
|
+
@table_row1.person1.should be nil
|
121
|
+
@table_row1.person1 = "John"
|
122
|
+
@table_row1.person1.should == "John"
|
123
|
+
@sheet[13,1].Value.should == "John"
|
124
|
+
@table_row1.Person1 = "Herbert"
|
125
|
+
@table_row1.Person1.should == "Herbert"
|
126
|
+
@sheet[13,1].Value.should == "Herbert"
|
127
|
+
@table_row1.win_sales.should be nil
|
128
|
+
@table_row1.win_sales = 42
|
129
|
+
@table_row1.win_sales.should == 42
|
130
|
+
@sheet[13,2].Value.should == 42
|
131
|
+
@table_row1.Win_Sales = 80
|
132
|
+
@table_row1.Win_Sales.should == 80
|
133
|
+
@sheet[13,2].Value.should == 80
|
134
|
+
@table_row1.xiq_xs.should == nil
|
135
|
+
@table_row1.xiq_xs = 90
|
136
|
+
@table_row1.xiq_xs.should == 90
|
137
|
+
@sheet[13,3].Value.should == 90
|
138
|
+
@table_row1.xiq_Xs = 100
|
139
|
+
@table_row1.xiq_Xs.should == 100
|
140
|
+
@sheet[13,3].Value.should == 100
|
141
|
+
@table_row1.order_id.should == nil
|
142
|
+
@table_row1.order_id = 1
|
143
|
+
@table_row1.order_id.should == 1
|
144
|
+
@sheet[13,4].Value.should == 1
|
145
|
+
@table_row1.OrderID = 2
|
146
|
+
@table_row1.OrderID.should == 2
|
147
|
+
@sheet[13,4].Value.should == 2
|
148
|
+
@table_row1.year = 1984
|
149
|
+
@table_row1.year.should == 1984
|
150
|
+
@sheet[13,5].Value.should == 1984
|
151
|
+
@table_row1.YEAR = 2020
|
152
|
+
@table_row1.YEAR.should == 2020
|
153
|
+
@sheet[13,5].Value.should == 2020
|
154
|
+
@table_row1.length_in_m.should == nil
|
155
|
+
@table_row1.length_in_m = 20
|
156
|
+
@table_row1.length_in_m.should == 20
|
157
|
+
@sheet[13,6].Value.should == 20
|
158
|
+
@table_row1.length_in_m = 40
|
159
|
+
@table_row1.length_in_m.should == 40
|
160
|
+
@sheet[13,6].Value.should == 40
|
161
|
+
@table_row1.amo_unt_sal___es.should == nil
|
162
|
+
@table_row1.amo_unt_sal___es = 80
|
163
|
+
@table_row1.amo_unt_sal___es.should == 80
|
164
|
+
@sheet[13,7].Value.should == 80
|
165
|
+
end
|
111
166
|
|
112
|
-
before do
|
113
|
-
@table = Table.new(@sheet, "table_name", [1,1], 3, ["Person","Amo%untSales"])
|
114
|
-
@table_row1 = @table[1]
|
115
167
|
end
|
116
168
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
169
|
+
context "with umlauts" do
|
170
|
+
|
171
|
+
before do
|
172
|
+
@table = Table.new(@sheet, "table_name", [1,1], 3, ["Verkäufer", "Straße", "area in m²"])
|
173
|
+
@table_row1 = @table[1]
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should read and set values via alternative column names" do
|
177
|
+
@table_row1.verkaeufer.should be nil
|
178
|
+
@table_row1.verkaeufer = "John"
|
179
|
+
@table_row1.verkaeufer.should == "John"
|
180
|
+
@sheet[2,1].Value.should == "John"
|
181
|
+
@table_row1.Verkaeufer = "Herbert"
|
182
|
+
@table_row1.Verkaeufer.should == "Herbert"
|
183
|
+
@sheet[2,1].Value.should == "Herbert"
|
184
|
+
@table_row1.strasse.should be nil
|
185
|
+
@table_row1.strasse = 42
|
186
|
+
@table_row1.strasse.should == 42
|
187
|
+
@sheet[2,2].Value.should == 42
|
188
|
+
@table_row1.Strasse = 80
|
189
|
+
@table_row1.Strasse.should == 80
|
190
|
+
@sheet[2,2].Value.should == 80
|
191
|
+
@table_row1.area_in_m3.should be nil
|
192
|
+
@table_row1.area_in_m3 = 10
|
193
|
+
@table_row1.area_in_m3.should == 10
|
194
|
+
@sheet[2,3].Value.should == 10
|
195
|
+
end
|
196
|
+
|
132
197
|
end
|
133
198
|
|
134
199
|
end
|
data/spec/range_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
2
|
+
require_relative 'spec_helper'
|
3
3
|
|
4
4
|
include RobustExcelOle
|
5
5
|
include General
|
@@ -73,19 +73,6 @@ describe RobustExcelOle::Range do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
it "should work with [] doing cashing synchonized, from #each to #[]" do
|
77
|
-
@range2[0].Value.should == 'simple'
|
78
|
-
@range2[1].Value.should == 'file'
|
79
|
-
@range2[2].Value.should == 'sheet2'
|
80
|
-
i = 0
|
81
|
-
@range2.each do |cell|
|
82
|
-
cell.Value = 'foo' if i == 0
|
83
|
-
cell.Value = 'bar' if i == 1
|
84
|
-
cell.Value = 'simple' if i == 2
|
85
|
-
i += 1
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
76
|
end
|
90
77
|
|
91
78
|
describe "#values" do
|
data/spec/spec_helper.rb
CHANGED
data/spec/workbook_spec.rb
CHANGED
@@ -1,33 +1,13 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../spec_helper'
|
4
4
|
|
5
5
|
$VERBOSE = nil
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=begin
|
16
|
-
$VERBOSE = nil
|
17
|
-
|
18
|
-
include General
|
19
|
-
|
20
|
-
unless Object.method_defined?(:require_relative)
|
21
|
-
def require_relative path
|
22
|
-
require File.expand_path(path, File.dirname(__FILE__))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require_relative "workbook_open_spec"
|
27
|
-
require_relative "workbook_close_spec"
|
28
|
-
require_relative "workbook_save_spec"
|
29
|
-
require_relative "workbook_misc_spec"
|
30
|
-
require_relative "workbook_sheet_spec"
|
31
|
-
require_relative "workbook_unobtr_spec"
|
32
|
-
require_relative "workbook_subclass_spec"
|
33
|
-
=end
|
7
|
+
require_relative 'workbook_open_spec'
|
8
|
+
require_relative 'workbook_close_spec'
|
9
|
+
require_relative 'workbook_save_spec'
|
10
|
+
require_relative 'workbook_misc_spec'
|
11
|
+
require_relative 'workbook_sheet_spec'
|
12
|
+
require_relative 'workbook_unobtr_spec'
|
13
|
+
require_relative 'workbook_subclass_spec'
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../spec_helper'
|
5
4
|
|
6
5
|
$VERBOSE = nil
|
7
6
|
|
8
7
|
include RobustExcelOle
|
9
8
|
include General
|
10
9
|
|
10
|
+
using ToReoRefinement
|
11
|
+
|
11
12
|
describe Workbook do
|
12
13
|
|
13
14
|
before(:all) do
|
@@ -24,7 +25,6 @@ describe Workbook do
|
|
24
25
|
@different_file = @dir + '/different_workbook.xls'
|
25
26
|
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
26
27
|
@another_simple_file = @dir + '/another_workbook.xls'
|
27
|
-
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
28
|
@simple_file_xlsm = @dir + '/workbook.xls'
|
29
29
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
30
|
@simple_file1 = @simple_file
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../spec_helper'
|
4
4
|
|
5
5
|
|
6
6
|
$VERBOSE = nil
|
@@ -24,7 +24,6 @@ describe Workbook do
|
|
24
24
|
@different_file = @dir + '/different_workbook.xls'
|
25
25
|
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
26
26
|
@another_simple_file = @dir + '/another_workbook.xls'
|
27
|
-
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
27
|
@simple_file_xlsm = @dir + '/workbook.xlsm'
|
29
28
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
29
|
@simple_file1 = @simple_file
|
@@ -43,6 +42,10 @@ describe Workbook do
|
|
43
42
|
@simple_file_hostname_share_path_other_path1 = @simple_file_hostname_share_path_other_path
|
44
43
|
@simple_file_xlsm1 = @simple_file_xlsm
|
45
44
|
@simple_file_xlsx1 = @simple_file_xlsx
|
45
|
+
#@linked_file = @dir + '/workbook_linked.xlsm'
|
46
|
+
#@sub_file = @dir + '/workbook_sub.xlsm'
|
47
|
+
@main_file = @dir + '/workbook_linked3.xlsm'
|
48
|
+
@sub_file = @dir + '/workbook_linked_sub.xlsm'
|
46
49
|
@error_message_excel = "provided Excel option value is neither an Excel object nor a valid option"
|
47
50
|
end
|
48
51
|
|
@@ -51,6 +54,45 @@ describe Workbook do
|
|
51
54
|
rm_tmp(@dir)
|
52
55
|
end
|
53
56
|
|
57
|
+
describe "linked workbooks" do
|
58
|
+
|
59
|
+
context "standard" do
|
60
|
+
|
61
|
+
before do
|
62
|
+
@book1 = Workbook.open(@main_file)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should open the main workbook and the linked workbook" do
|
66
|
+
@book1.should be_alive
|
67
|
+
@book1.should be_a Workbook
|
68
|
+
@book1.filename.should == @main_file
|
69
|
+
Excel.current.workbooks.map{|b| b.filename}.should == [@main_file, @sub_file]
|
70
|
+
book2 = Workbook.open(@sub_file)
|
71
|
+
book2.should be_alive
|
72
|
+
book2.should be_a Workbook
|
73
|
+
book2.filename.should == @sub_file
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should close the main workbook" do
|
77
|
+
@book1.close
|
78
|
+
Excel.current.workbooks.map{|b| b.filename}.should == [@sub_file]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should raise error when trying to close the linked workbook" do
|
82
|
+
book2 = Workbook.open(@sub_file)
|
83
|
+
expect{
|
84
|
+
book2.close
|
85
|
+
}.to raise_error(WorkbookLinked)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should raise error when trying to change the read-only mode of the linked workbook" do
|
89
|
+
expect{
|
90
|
+
book2 = Workbook.open(@sub_file, :read_only => true)
|
91
|
+
}.to raise_error(WorkbookLinked)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
54
96
|
describe "basic tests with xlsx-workbooks" do
|
55
97
|
|
56
98
|
context "with simple file" do
|
@@ -2631,8 +2673,6 @@ describe Workbook do
|
|
2631
2673
|
@book.should be_alive
|
2632
2674
|
end
|
2633
2675
|
|
2634
|
-
|
2635
|
-
|
2636
2676
|
it "should not open the new book and not close the unsaved book, if user answers 'no'" do
|
2637
2677
|
# "No" is right to "Yes" (the default). --> language independent
|
2638
2678
|
# strangely, in the "no" case, the question will sometimes be repeated three time
|
@@ -2984,7 +3024,7 @@ describe Workbook do
|
|
2984
3024
|
context "with various file formats" do
|
2985
3025
|
|
2986
3026
|
it "should open linked workbook" do
|
2987
|
-
book = Workbook.open(@
|
3027
|
+
book = Workbook.open(@main_file, :visible => true)
|
2988
3028
|
book.close
|
2989
3029
|
end
|
2990
3030
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../spec_helper'
|
4
4
|
|
5
5
|
|
6
6
|
$VERBOSE = nil
|
@@ -24,8 +24,10 @@ describe Workbook do
|
|
24
24
|
@different_file = @dir + '/different_workbook.xls'
|
25
25
|
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
26
26
|
@another_simple_file = @dir + '/another_workbook.xls'
|
27
|
-
|
28
|
-
|
27
|
+
#@main_file = @dir + '/workbook_linked.xlsm'
|
28
|
+
#@linked_sub_file = @dir + '/workbook_sub.xlsm'
|
29
|
+
@main_file = @dir + '/workbook_linked3.xlsm'
|
30
|
+
@sub_file = @dir + '/workbook_linked_sub.xlsm'
|
29
31
|
@simple_file_xlsm = @dir + '/workbook.xlsm'
|
30
32
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
31
33
|
@simple_file1 = @simple_file
|
@@ -231,41 +233,7 @@ describe Workbook do
|
|
231
233
|
end
|
232
234
|
|
233
235
|
describe "Workbook.for_reading, for_modifying" do
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
236
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
237
|
context "with open writable book" do
|
270
238
|
|
271
239
|
before do
|
@@ -336,56 +304,66 @@ describe Workbook do
|
|
336
304
|
|
337
305
|
end
|
338
306
|
|
339
|
-
describe "with referenced
|
307
|
+
describe "with referenced workbooks" do
|
340
308
|
|
341
309
|
context "with no books" do
|
342
310
|
|
343
|
-
it "should open in read-only" do
|
344
|
-
Workbook.unobtrusively(@
|
311
|
+
it "should open the linked workbook in read-only" do
|
312
|
+
Workbook.unobtrusively(@sub_file, :writable => false) do |book|
|
345
313
|
book.ReadOnly.should be true
|
346
|
-
book.filename.should == @
|
314
|
+
book.filename.should == @sub_file
|
347
315
|
end
|
316
|
+
Excel.current.workbooks.should == []
|
348
317
|
end
|
349
318
|
|
350
|
-
it "should
|
319
|
+
it "should open the workbook and its linked workbook in read-only" do
|
320
|
+
Workbook.unobtrusively(@main_file, :writable => false) do |book|
|
321
|
+
book.ReadOnly.should be true
|
322
|
+
book.filename.should == @main_file
|
323
|
+
book.excel.workbooks.map{|b| b.filename}.should == [@sub_file, @main_file]
|
324
|
+
end
|
325
|
+
Excel.current.workbooks.map{|b| b.filename}.should == [@sub_file]
|
326
|
+
end
|
351
327
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
328
|
+
it "should not write the linked workbook and close it" do
|
329
|
+
Workbook.unobtrusively(@sub_file, :writable => false) do |book|
|
330
|
+
book.ReadOnly.should be true
|
331
|
+
book.filename.should == @sub_file
|
332
|
+
@old_value = book.sheet(1)[1,1].Value
|
333
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
334
|
+
end
|
335
|
+
Excel.current.workbooks.should == []
|
336
|
+
end
|
359
337
|
|
338
|
+
it "should not write the main workbook and close the linked file as well" do
|
339
|
+
Workbook.unobtrusively(@main_file, :writable => false) do |book|
|
340
|
+
book.ReadOnly.should be true
|
341
|
+
book.filename.should == @main_file
|
342
|
+
@old_value = book.sheet(1)[1,1].Value
|
343
|
+
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
344
|
+
end
|
345
|
+
Excel.current.workbooks.map{|b| b.filename}.should == [@sub_file]
|
360
346
|
end
|
347
|
+
|
361
348
|
end
|
362
349
|
|
363
350
|
context "with open books" do
|
364
351
|
|
365
352
|
before do
|
366
|
-
@book_main = Workbook.open(@
|
367
|
-
@book_sub = Workbook.open(@linked_sub_file)
|
353
|
+
@book_main = Workbook.open(@main_file)
|
368
354
|
end
|
369
355
|
|
370
356
|
it "should leave the read-only mode" do
|
371
|
-
Workbook.unobtrusively(@
|
357
|
+
Workbook.unobtrusively(@sub_file, :read_only_default => true) do |book|
|
372
358
|
book.ReadOnly.should be false
|
373
|
-
book.should == @book_sub
|
374
|
-
book.filename.should == @book_sub.filename
|
375
|
-
book.excel.should == @book_sub.excel
|
376
359
|
end
|
377
360
|
end
|
378
361
|
|
379
362
|
it "should force to read-only" do
|
380
363
|
expect{
|
381
|
-
Workbook.unobtrusively(@
|
382
|
-
book.ReadOnly.should be true
|
383
|
-
book.should == @book_sub
|
384
|
-
book.filename.should == @book_sub.filename
|
385
|
-
book.excel.should == @book_sub.excel
|
386
|
-
book.sheet(1)[1,1] = book.sheet(1)[1,1].Value == "foo" ? "bar" : "foo"
|
364
|
+
Workbook.unobtrusively(@sub_file, :read_only => true) do
|
387
365
|
end
|
388
|
-
|
366
|
+
}.to raise_error(WorkbookLinked)
|
389
367
|
end
|
390
368
|
end
|
391
369
|
end
|