robust_excel_ole 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,12 +23,14 @@ describe Book do
23
23
  @simple_save_file = @dir + '/workbook_save.xls'
24
24
  @different_file = @dir + '/different_workbook.xls'
25
25
  @simple_file_other_path = @dir + '/more_data/workbook.xls'
26
+ @another_simple_file_other_path = @dir + '/more_data/another_workbook.xls'
26
27
  @another_simple_file = @dir + '/another_workbook.xls'
27
28
  @linked_file = @dir + '/workbook_linked.xlsm'
28
29
  @simple_file_xlsm = @dir + '/workbook.xls'
29
30
  @simple_file_xlsx = @dir + '/workbook.xlsx'
30
31
  @simple_file1 = @simple_file
31
32
  @simple_file_other_path1 = @simple_file_other_path
33
+ @another_simple_file_other_path1 = @another_simple_file_other_path
32
34
  @simple_save_file1 = @simple_save_file
33
35
  end
34
36
 
@@ -135,6 +137,23 @@ describe Book do
135
137
  end
136
138
  end
137
139
 
140
+ context "with saving with the same name in another directory" do
141
+
142
+ before do
143
+ @book = Book.open(@simple_file1)
144
+ end
145
+
146
+ it "should save with the same name in another directory" do
147
+ File.delete @simple_file_other_path1 rescue nil
148
+ File.open(@simple_file_other_path1,"w") do | file |
149
+ file.puts "garbage"
150
+ end
151
+ File.exist?(@simple_file_other_path1).should be_true
152
+ @book.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
153
+ end
154
+
155
+ end
156
+
138
157
  context "with blocked by another file" do
139
158
 
140
159
  before do
@@ -120,20 +120,62 @@ describe Book do
120
120
  Book.unobtrusively(@simple_file, :visible => true) do |book|
121
121
  book.should be_a Book
122
122
  book.should be_alive
123
- book.excel.visible.should be_true
123
+ book.excel.Visible.should be_true
124
+ book.Windows(book.Name).Visible.should be_true
124
125
  end
125
126
  end
126
127
 
127
- it "should be visible" do
128
+ it "should be visible and displayalerts" do
128
129
  excel = Excel.new(:reuse => false, :displayalerts => true)
129
130
  Book.unobtrusively(@simple_file, :visible => true) do |book|
130
131
  book.should be_a Book
131
132
  book.should be_alive
132
- book.excel.visible.should be_true
133
- book.excel.displayalerts.should be_true
133
+ book.excel.Visible.should be_true
134
+ book.Windows(book.Name).Visible.should be_true
135
+ book.excel.DisplayAlerts.should be_true
136
+ end
137
+ end
138
+
139
+ it "should do default-visible" do
140
+ excel = Excel.new(:reuse => false, :visible => false)
141
+ Book.unobtrusively(@simple_file, :default => {:visible => true}) do |book|
142
+ book.should be_a Book
143
+ book.should be_alive
144
+ book.excel.Visible.should_not be_true
145
+ book.Windows(book.Name).Visible.should be_true
146
+ end
147
+ end
148
+
149
+ it "should do default-invisible" do
150
+ excel = Excel.new(:reuse => false, :visible => true)
151
+ Book.unobtrusively(@simple_file, :default => {:visible => false}) do |book|
152
+ book.should be_a Book
153
+ book.should be_alive
154
+ book.excel.Visible.should be_true
155
+ book.Windows(book.Name).Visible.should be_false
156
+ end
157
+ end
158
+
159
+ it "should do force-visible" do
160
+ excel = Excel.new(:reuse => false, :visible => false)
161
+ Book.unobtrusively(@simple_file, :force => {:visible => true}) do |book|
162
+ book.should be_a Book
163
+ book.should be_alive
164
+ book.excel.Visible.should be_true
165
+ book.Windows(book.Name).Visible.should be_true
134
166
  end
135
167
  end
136
168
 
169
+ it "should do force-invisible" do
170
+ excel = Excel.new(:reuse => false, :visible => true)
171
+ Book.unobtrusively(@simple_file, :force => {:visible => false}) do |book|
172
+ book.should be_a Book
173
+ book.should be_alive
174
+ book.excel.Visible.should be_true
175
+ book.Windows(book.Name).Visible.should be_false
176
+ end
177
+ end
178
+
137
179
  end
138
180
 
139
181
  context "with an open book" do
Binary file
Binary file
Binary file
Binary file
data/spec/excel_spec.rb CHANGED
@@ -1277,61 +1277,128 @@ module RobustExcelOle
1277
1277
 
1278
1278
  end
1279
1279
 
1280
+ context "with screen updating" do
1281
+
1282
+ it "should set screen updating" do
1283
+ excel1 = Excel.new
1284
+ excel1.ScreenUpdating.should be_true
1285
+ excel2 = Excel.create(:screenupdating => false)
1286
+ excel2.ScreenUpdating.should be_false
1287
+ excel3 = Excel.new
1288
+ excel3.ScreenUpdating.should be_true
1289
+ excel4 = Excel.new(:screenupdating => false)
1290
+ excel4.ScreenUpdating.should be_false
1291
+ end
1292
+
1293
+ end
1294
+
1280
1295
  context "with calculation" do
1281
1296
 
1282
- before do
1283
- @excel1 = Excel.new
1297
+ it "should create and reuse Excel with calculation mode" do
1298
+ excel1 = Excel.create(:calculation => :manual)
1299
+ excel1.calculation.should == :manual
1300
+ excel2 = Excel.create(:calculation => :automatic)
1301
+ excel2.calculation.should == :automatic
1302
+ excel3 = Excel.current
1303
+ excel3.calculation.should == :manual
1304
+ excel4 = Excel.current(:calculation => :automatic)
1305
+ excel4.calculation.should == :automatic
1306
+ excel5 = Excel.new(:reuse => false)
1307
+ excel5.calculation.should == nil
1308
+ excel6 = Excel.new(:reuse => false, :calculation => :manual)
1309
+ excel6.calculation.should == :manual
1284
1310
  end
1285
1311
 
1286
- it "should not set calculation mode when no workbook is opened" do
1312
+ it "should do with_calculation mode without workbooks" do
1313
+ @excel1 = Excel.new
1287
1314
  old_calculation_mode = @excel1.Calculation
1315
+ old_calculatebeforesave = @excel1.CalculateBeforeSave
1288
1316
  @excel1.with_calculation(:automatic) do
1289
1317
  @excel1.Calculation.should == old_calculation_mode
1318
+ @excel1.CalculateBeforeSave.should == old_calculatebeforesave
1290
1319
  end
1291
1320
  @excel1.with_calculation(:manual) do
1292
1321
  @excel1.Calculation.should == old_calculation_mode
1322
+ @excel1.CalculateBeforeSave.should == old_calculatebeforesave
1293
1323
  end
1294
- @excel1.set_calculation(:automatic)
1295
- @excel1.Calculation.should == old_calculation_mode
1296
- @excel1.set_calculation(:manual)
1324
+ end
1325
+
1326
+ it "should set calculation mode without workbooks" do
1327
+ @excel1 = Excel.new
1328
+ old_calculation_mode = @excel1.Calculation
1329
+ old_calculatebeforesave = @excel1.CalculateBeforeSave
1330
+ @excel1.calculation = :automatic
1331
+ @excel1.calculation.should == :automatic
1332
+ @excel1.Calculation.should == old_calculation_mode
1333
+ @excel1.CalculateBeforeSave.should == old_calculatebeforesave
1334
+ @excel1.calculation = :manual
1335
+ @excel1.calculation.should == :manual
1297
1336
  @excel1.Calculation.should == old_calculation_mode
1337
+ @excel1.CalculateBeforeSave.should == old_calculatebeforesave
1298
1338
  end
1299
1339
 
1300
- it "should set calculation mode to manual and reset to the previous value" do
1301
- b = Book.open(@simple_file)
1302
- calculation_mode_old = @excel1.Calculation
1303
- calculation_before_save_old = @excel1.CalculateBeforeSave
1340
+ it "should do with_calculation with workbook" do
1341
+ @excel1 = Excel.new
1342
+ book = Book.open(@simple_file)
1343
+ book.Windows(book.Name).Visible = true
1344
+ old_calculation_mode = @excel1.Calculation
1304
1345
  @excel1.with_calculation(:manual) do
1346
+ @excel1.calculation.should == :manual
1305
1347
  @excel1.Calculation.should == -4135
1306
1348
  @excel1.CalculateBeforeSave.should be_false
1307
1349
  end
1308
- @excel1.Calculation.should == calculation_mode_old
1309
- @excel1.CalculateBeforeSave.should == calculation_before_save_old
1350
+ @excel1.Calculation.should == old_calculation_mode
1351
+ @excel1.CalculateBeforeSave.should be_false
1352
+ @excel1.with_calculation(:automatic) do
1353
+ @excel1.calculation.should == :automatic
1354
+ @excel1.Calculation.should == -4105
1355
+ @excel1.CalculateBeforeSave.should be_false
1356
+ end
1357
+ @excel1.Calculation.should == old_calculation_mode
1358
+ @excel1.CalculateBeforeSave.should be_false
1310
1359
  end
1311
1360
 
1312
- it "should set calculation mode to manual" do
1313
- b = Book.open(@simple_file)
1314
- calculation_mode_old = @excel1.Calculation
1315
- calculation_before_save_old = @excel1.CalculateBeforeSave
1316
- @excel1.set_calculation(:manual)
1361
+ it "should set calculation mode to manual with workbook" do
1362
+ @excel1 = Excel.new
1363
+ book = Book.open(@simple_file)
1364
+ book.Windows(book.Name).Visible = true
1365
+ @excel1.calculation = :manual
1366
+ @excel1.calculation.should == :manual
1317
1367
  @excel1.Calculation.should == -4135
1318
1368
  @excel1.CalculateBeforeSave.should be_false
1319
1369
  end
1320
1370
 
1321
- it "should set calculation mode automatic" do
1371
+ it "should set calculation mode to automatic with workbook" do
1372
+ @excel1 = Excel.new
1373
+ book = Book.open(@simple_file)
1374
+ book.Windows(book.Name).Visible = true
1375
+ @excel1.calculation = :automatic
1376
+ @excel1.calculation.should == :automatic
1377
+ @excel1.Calculation.should == -4105
1378
+ @excel1.CalculateBeforeSave.should be_false
1379
+ end
1380
+
1381
+ it "should set Calculation without workbooks" do
1382
+ @excel1 = Excel.new
1383
+ expect{
1384
+ @excel1.Calculation = -4135
1385
+ }.to raise_error(WIN32OLERuntimeError)
1386
+ end
1387
+
1388
+ it "should do Calculation to manual with workbook" do
1389
+ @excel1 = Excel.new
1322
1390
  b = Book.open(@simple_file)
1323
- @excel1.with_calculation(:automatic) do
1324
- @excel1.Calculation.should == -4105
1325
- @excel1.CalculateBeforeSave.should be_true
1326
- end
1391
+ @excel1.Calculation = -4135
1392
+ @excel1.calculation.should == :manual
1393
+ @excel1.Calculation.should == -4135
1327
1394
  end
1328
1395
 
1329
- it "should set calculation mode to automatic as default" do
1396
+ it "should do Calculation to automatic with workbook" do
1397
+ @excel1 = Excel.new
1330
1398
  b = Book.open(@simple_file)
1331
- @excel1.with_calculation do
1332
- @excel1.Calculation.should == -4105
1333
- @excel1.CalculateBeforeSave.should be_true
1334
- end
1399
+ @excel1.Calculation = -4105
1400
+ @excel1.calculation.should == :automatic
1401
+ @excel1.Calculation.should == -4105
1335
1402
  end
1336
1403
 
1337
1404
  end
@@ -1359,8 +1426,9 @@ module RobustExcelOle
1359
1426
  context "with hwnd and hwnd2excel" do
1360
1427
 
1361
1428
  before do
1362
- @excel1 = Excel.new
1363
- @excel2 = Excel.new(:reuse => false)
1429
+ Excel.kill_all
1430
+ @excel1 = Excel.new(:visible => true)
1431
+ @excel2 = Excel.new(:reuse => false, :visible => false)
1364
1432
  end
1365
1433
 
1366
1434
  it "should yield the correct hwnd" do
@@ -1374,8 +1442,42 @@ module RobustExcelOle
1374
1442
  excel4 = Excel.hwnd2excel(@excel2.hwnd)
1375
1443
  @excel1.should == excel3
1376
1444
  @excel2.should == excel4
1377
- excel3.should_not == excel4
1445
+ excel3.should_not == excel4
1446
+ end
1447
+
1448
+ =begin
1449
+ # does not work yet
1450
+ it "should not say 'probably recycled'" do
1451
+ e1_hwnd = @excel1.hwnd
1452
+ @excel1.close_workbooks
1453
+ weak_xl = WeakRef.new(@excel1.ole_excel)
1454
+ @excel1.Quit
1455
+ @excel1 = nil
1456
+ GC.start
1457
+ sleep 2
1458
+ process_id = Win32API.new("user32", "GetWindowThreadProcessId", ["I","P"], "I")
1459
+ pid_puffer = " " * 32
1460
+ process_id.call(e1_hwnd, pid_puffer)
1461
+ pid = pid_puffer.unpack("L")[0]
1462
+ begin
1463
+ Process.kill("KILL", pid)
1464
+ rescue
1465
+ trace "kill_error: #{$!}"
1466
+ end
1467
+ if weak_xl.weakref_alive? then
1468
+ #if WIN32OLE.ole_reference_count(weak_xlapp) > 0
1469
+ begin
1470
+ #weak_xl.ole_free
1471
+ rescue
1472
+ trace "weakref_probl_olefree"
1473
+ end
1474
+ end
1475
+ excel5 = Excel.new(:reuse => false)
1476
+ e1_again = Excel.hwnd2excel(e1_hwnd)
1477
+ e1_again.Hwnd.should == e1_hwnd
1478
+ e1_again.should == nil
1378
1479
  end
1480
+ =end
1379
1481
  end
1380
1482
 
1381
1483
  describe "generate workbook" do
@@ -1447,6 +1549,7 @@ module RobustExcelOle
1447
1549
 
1448
1550
  before do
1449
1551
  @book1 = Book.open(@dir + '/another_workbook.xls')
1552
+ @book1.Windows(@book1.Name).Visible = true
1450
1553
  @excel1 = @book1.excel
1451
1554
  end
1452
1555
 
@@ -1480,7 +1583,7 @@ module RobustExcelOle
1480
1583
  excel2.nameval("one")
1481
1584
  }.to raise_error(NameNotFound, /cannot find name "one"/)
1482
1585
  expect {
1483
- excel3 = Excel.create
1586
+ excel3 = Excel.create(:visible => true)
1484
1587
  excel3["one"]
1485
1588
  }.to raise_error(NameNotFound, /cannot find name "one"/)
1486
1589
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- version: "1.0"
9
+ - 1
10
+ version: 1.0.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - traths
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2016-12-07 00:00:00 +01:00
18
+ date: 2017-04-16 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -34,10 +35,10 @@ dependencies:
34
35
  type: :development
35
36
  version_requirements: *id001
36
37
  description: |-
37
- RobustExcelOle automates modifying, reading and writing Excel files.
38
+ RobustExcelOle automates modifying, reading and writing Excel files in Windows by using the win32ole library.
38
39
  It supports simultaneously running Excel instances and user interactions.
39
40
  RobustExcelOle deals with various cases of Excel (and user) behaviour,
40
- supplies workarounds for some Excel bugs, and supports referenced libraries
41
+ supplies workarounds for some Excel bugs, and supports referenced libraries.
41
42
  email:
42
43
  - Thomas.Raths@gmx.net
43
44
  executables: []
@@ -55,6 +56,7 @@ files:
55
56
  - Guardfile
56
57
  - LICENSE
57
58
  - README.rdoc
59
+ - README_detail.rdoc
58
60
  - Rakefile
59
61
  - TodoList.md
60
62
  - examples/edit_sheets/example_access_sheets_and_cells.rb
@@ -114,7 +116,6 @@ files:
114
116
  - spec/data/merge_cells.xls
115
117
  - spec/data/more_data/workbook.xls
116
118
  - spec/data/protected_sheet.xls
117
- - spec/data/refed_wb.xls
118
119
  - spec/data/reference_workbook.xls
119
120
  - spec/data/referencing_wb.xls
120
121
  - spec/data/workbook.xls
Binary file