robust_excel_ole 1.11 → 1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +11 -0
  3. data/README.rdoc +20 -8
  4. data/docs/README_open.rdoc +1 -0
  5. data/docs/README_ranges.rdoc +5 -11
  6. data/examples/{introducing_examples/example_introducing.rb → introductory_examples/example_introductory.rb} +10 -2
  7. data/examples/{introducing_examples → introductory_examples}/example_open.rb +18 -17
  8. data/examples/{introducing_examples → introductory_examples}/example_range.rb +29 -16
  9. data/examples/modifying_sheets/example_access_sheets_and_cells.rb +8 -7
  10. data/examples/modifying_sheets/example_add_names.rb +4 -8
  11. data/examples/modifying_sheets/example_adding_sheets.rb +7 -6
  12. data/examples/modifying_sheets/example_concating.rb +2 -2
  13. data/examples/modifying_sheets/example_copying.rb +3 -3
  14. data/examples/modifying_sheets/example_expanding.rb +2 -2
  15. data/examples/modifying_sheets/example_naming.rb +2 -2
  16. data/examples/modifying_sheets/example_ranges.rb +4 -4
  17. data/examples/modifying_sheets/example_saving.rb +3 -3
  18. data/examples/open_save_close/example_control_to_excel.rb +10 -11
  19. data/examples/open_save_close/example_default_excel.rb +13 -14
  20. data/examples/open_save_close/example_force_excel.rb +9 -10
  21. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +7 -7
  22. data/examples/open_save_close/example_if_obstructed_forget.rb +5 -5
  23. data/examples/open_save_close/example_if_obstructed_save.rb +7 -7
  24. data/examples/open_save_close/example_if_unsaved_accept.rb +13 -13
  25. data/examples/open_save_close/example_if_unsaved_forget.rb +9 -10
  26. data/examples/open_save_close/example_if_unsaved_forget_more.rb +9 -10
  27. data/examples/open_save_close/example_read_only.rb +6 -6
  28. data/examples/open_save_close/example_rename_cells.rb +4 -5
  29. data/examples/open_save_close/example_reuse.rb +6 -6
  30. data/examples/open_save_close/example_simple.rb +5 -5
  31. data/examples/open_save_close/example_unobtrusively.rb +4 -4
  32. data/lib/robust_excel_ole/address.rb +0 -4
  33. data/lib/robust_excel_ole/bookstore.rb +4 -28
  34. data/lib/robust_excel_ole/excel.rb +17 -22
  35. data/lib/robust_excel_ole/general.rb +11 -18
  36. data/lib/robust_excel_ole/range_owners.rb +17 -27
  37. data/lib/robust_excel_ole/reo_common.rb +7 -3
  38. data/lib/robust_excel_ole/version.rb +1 -1
  39. data/lib/robust_excel_ole/workbook.rb +178 -180
  40. data/lib/robust_excel_ole/worksheet.rb +7 -4
  41. data/robust_excel_ole.gemspec +6 -4
  42. data/spec/bookstore_spec.rb +38 -34
  43. data/spec/data/more_data/workbook.xls +0 -0
  44. data/spec/excel_spec.rb +89 -44
  45. data/spec/general_spec.rb +1 -0
  46. data/spec/range_spec.rb +7 -4
  47. data/spec/workbook_specs/workbook_close_spec.rb +2 -1
  48. data/spec/workbook_specs/workbook_misc_spec.rb +34 -18
  49. data/spec/workbook_specs/workbook_open_spec.rb +112 -71
  50. data/spec/workbook_specs/workbook_save_spec.rb +173 -5
  51. data/spec/workbook_specs/workbook_sheet_spec.rb +6 -42
  52. data/spec/workbook_specs/workbook_unobtr_spec.rb +9 -246
  53. data/spec/worksheet_spec.rb +21 -5
  54. metadata +12 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 344c336ba61c5f1b98839047f69cbbac1ddef451291fa32260c47218421d78cc
4
- data.tar.gz: 169a63ca7cb3d582443aa046228797cc946e9f47f45e97019b21504f8a897384
3
+ metadata.gz: b568d18d573ee255b9c3601e983c3d7b1ff062fe50b97dc10bc1e9a79efb1556
4
+ data.tar.gz: 3f87e8db112deb8e414f77b2d5756158a79b135413ba6a1116d7b7abf68c710f
5
5
  SHA512:
6
- metadata.gz: dc9e189d01012805dd02d668c833e96b9597997b518a2b9ce6beb671969e007d8cae5d362a045fbd439a4368cf7ddfdfee66b535d60e9b4e9c68db7a99023989
7
- data.tar.gz: 1e04fa12bc2e5956fb0efa68a92b185557b8180909da820517ab55affd3bf8154d297aa9a2b0eaa8e8a161fc31972560ea74f5beefa2fc51225f45b392c122fc
6
+ metadata.gz: e3ba0806cf0f4c0fec0ae85eee158fe5b9422d901f9172ad4eb274a1118eaf7dc61a7e47cd0f5d276bacd40e0506b4d7531bbcd4d93334bfe1dc1242a3f803db
7
+ data.tar.gz: eb1ee24dcb77a5d7b84715b56352b43b7df7f3e2f64130761e911313b0cca921f2c8ca7a1ae3f64ef84e6c4933b21dc81097b759ed99abed64549b7ac26c56e2
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.12]
5
+
6
+ ### Added
7
+ - Workbook.open: option :if_unsaved => :save
8
+ - Workbook#color_if_modified
9
+
10
+ ### Changed:
11
+ - Workbook#save, save_as: no parameter +discoloring
12
+ - RangeOwners#set_namevalue, set_namevalue_glob, Worksheet#set_cellval:
13
+ no optional parameter for color
14
+
4
15
 
5
16
  ## [1.11]
6
17
 
data/README.rdoc CHANGED
@@ -1,11 +1,19 @@
1
1
  = RobustExcelOle
2
2
 
3
- This library automates reading, modifying, and writing Excel workbooks. It is designed to support several kinds of concurrency of both simultaneously running Excel instances and simultanously happening user interactions.
4
- RobustExcelOle deals with various cases of Excel and user behaviour,
5
- and implements workarounds for some Excel bugs.
6
- The gem provides convenient methods for common tasks, and facilitates referenced libraries.
3
+ RobustExcelOle helps controlling Excel.
4
+ This obviously includes standard tasks like reading and writing Excel workbooks.
5
+ The gem is designed to manage simultaneously running Excel instances, even with simultanously happening user interactions.
6
+
7
+ RobustExcelOle deals with various cases of Excel (and user) behaviour, and
8
+ supplies workarounds for some Excel and JRuby bugs.
9
+
10
+ It supports handling workbooks across Excel instances by keeping track of workbooks and instances. Conflicts are managed before Excel notices.
11
+
12
+ Library references are supported.
13
+
14
+ RobustExcelOle works by sending VBA methods via Win32OLE.
15
+ Therefore, it runs on Windows only.
7
16
 
8
- RobustExcelOle works by sending VBA methods via Win32OLE. It keeps track of Excel workbooks and Excel instances.
9
17
 
10
18
  == Requirements
11
19
 
@@ -226,7 +234,9 @@ Without the option +:default+, the workbook can be forced to be opened in the cu
226
234
 
227
235
  workbook2 = Workbook.open('spec/data/workbook.xls', :excel => excel1)
228
236
 
229
- As a further feature, RobustExcelOle allows processing workbooks, while still supporting user's interactions: The commands enable to open, close, reopen, read, modify, write and save Excel workbooks, without the need of the user's interaction, and even without the user noticing. Thus, while running a script containing RobustExcelOle commands, the user can open and process workbooks in any Excel instances at any time. RobustExcelOle manages the complex cases of conflicts that might occur such that the user does not need to interfere and the script can continue.
237
+ === Managing conflicts with unsaved and blocking workbooks
238
+
239
+ RobustExcelOle enables processing workbooks, while still supporting user's interactions: The commands enable to open, close, reopen, read, modify, write and save Excel workbooks, without the need of the user's interaction, and even without the user noticing. Thus, while running a script containing RobustExcelOle commands, the user can open and process workbooks in any Excel instances at any time. RobustExcelOle manages the complex cases of conflicts that might occur such that the user does not need to interfere and the script can continue.
230
240
 
231
241
  For example, suppose we want to process a list of workbooks. RobustExcelOle allows to rapidly open, manipulate, close and save these workbooks. Now assume, the workbook "workbook.xls" is being processed, while the user has already opened this workbook, has modified but not saved it yet. Excel would prompt a message and ask the user what to do. RobustExcelOle solves this conflict by using an option that states whether the changes of the user should be saved (accepted) or discarded (forgotten) before opening the workbook, e.g.
232
242
 
@@ -309,11 +319,13 @@ For more details about reading and writing contents of cells and ranges see {REA
309
319
 
310
320
  === Running in jruby
311
321
 
312
- RobustExcelOle runs in jruby as well. You can call the console via the command +jreo+. However, note that, due to some restrictions of the library jruby-win32ole, there are some restrictions. So we had implemented some adaptions and workarounds. Some issues still remain when running under jruby:
322
+ RobustExcelOle runs in jruby as well. You can call the console via the command +jreo+. We implemented workarounds to cope with some restrictions of the library jruby-win32ole. Some issues still remain when running under jruby. So you might consider the following points when running RobustExcelOle under jruby:
313
323
 
314
- 1. Excel.current or Excel.new(:reuse => true) does not connect to an already running Excel instance, unless some workbook has been opened via RobustExcelOle. 2. Excel.kill_all does work, Excel.close_all does not work. 3. When providing an absolute path, you have to state the "/" ("C:/abc.xls" works, "C:abc" does not work).
324
+ 1. +Excel.current+ or +Excel.new(:reuse => true)+ does not connect to an already running Excel instance, unless some workbook has been opened via RobustExcelOle.
315
325
 
326
+ 2. Use +Excel.kill_all+ instead of +Excel.close_all+. +Excel.close_all does not work yet. It relies on stepping through all heap objects in ObjectSpace. In jruby ObjectSpace is disabled. Each_object will only work with Class.
316
327
 
328
+ 3. When providing an absolute path, you have to state the "/" ("C:/abc.xls" works, "C:abc" does not work).
317
329
 
318
330
  === More things
319
331
 
@@ -55,6 +55,7 @@ If a workbook contains unsaved changes and a new workbook with the same file nam
55
55
  +:raise+:: Raise an exeption. Don't open the workbook.
56
56
  +:accept+:: Let the unsaved workbook open.
57
57
  +:forget+:: Discard any changes and reopen the workbook.
58
+ +:save+:: Save any changes and reopen the workbook
58
59
  +:new_excel+:: Open the new workbook in a new Excel instance
59
60
  +:alert+:: Give control to Excel.
60
61
 
@@ -306,9 +306,10 @@ or
306
306
 
307
307
  book.set_namevalue_glob("name", "new_value")
308
308
 
309
- The method []= colors the written cell. You can specify the color of a changed range via the method +set_namevalue_glob+.
310
-
311
- book.set_namevalue_glob("name", "new_value", :color => 4)
309
+ The method []= colors the written cell, if you have specified the color of the changed range via the method Workbook#color before, e.g.
310
+
311
+ book.color_if_modified = 4
312
+ book["name"] = "new_value"
312
313
 
313
314
  Similarly, the contents of a named range can be read and modified in a worksheet
314
315
 
@@ -328,13 +329,6 @@ or an Application object.
328
329
 
329
330
  excel["name"] = "new_value"
330
331
 
331
- When saving, the written cells get discolored when using the option :discoloring
332
-
333
- book.save(:discoloring => true)
334
-
335
- or
336
-
337
- book.save_as('spec/data/workbook.xls', :discoloring => true)
338
332
 
339
333
  === Reading and writing the contents of a range with a locally defined name
340
334
 
@@ -378,7 +372,7 @@ Similarly, you can write a cell.
378
372
 
379
373
  or
380
374
 
381
- sheet.set_cellval(1,1,"new_value", :color => 42)
375
+ sheet.set_cellval(1,1,"new_value")
382
376
 
383
377
  === Accessing rows and columns
384
378
 
@@ -1,7 +1,7 @@
1
1
  # introducing example
2
2
 
3
- require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
4
- require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
3
+ require_relative '../../lib/robust_excel_ole'
4
+ require_relative '../../spec/helpers/create_temporary_dir'
5
5
  require "fileutils"
6
6
 
7
7
  include RobustExcelOle
@@ -13,6 +13,8 @@ Excel.kill_all
13
13
 
14
14
  # Let's open a workbook.
15
15
  workbook = Workbook.open simple_file
16
+ # make it visible
17
+ workbook.visible = true
16
18
  # put name of the workbook
17
19
  puts "name: #{workbook.Name}"
18
20
  value = workbook['firstcell']
@@ -20,23 +22,29 @@ puts "value: #{value}"
20
22
  # assigning a new value
21
23
  workbook['firstcell'] = "new"
22
24
  # saving the workbook
25
+ puts "save the workbook"
23
26
  workbook.save
24
27
  # closing the workbook
28
+ puts "close the workbook"
25
29
  workbook.close
26
30
  # reopening the workbook
31
+ puts "reopen the workbook"
27
32
  workbook.reopen
28
33
  # further operations
29
34
  workbook['firstcell'] = "another_value"
30
35
  # saved status of the workbook
31
36
  puts "saved: #{workbook.Saved}"
32
37
  # unobtrusively reading a workbook
38
+ puts "unobtrusively reading the workbook"
33
39
  Workbook.for_reading(simple_file) do |workbook|
34
40
  puts "value of first cell: #{workbook['firstcell']}"
35
41
  end
36
42
  puts "saved: #{workbook.Saved}"
37
43
  # unobtrusively modifying a workbook
44
+ puts "unobtrusively modifying the workbook"
38
45
  Workbook.for_modifying(simple_file) do |workbook|
39
46
  workbook['firstcell'] = "bar"
40
47
  end
41
48
  puts "saved: #{workbook.Saved}"
42
49
  puts "value of first cell: #{workbook['firstcell']}"
50
+ Excel.kill_all
@@ -1,7 +1,7 @@
1
1
  # introducing example example_open.rb
2
2
 
3
- require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
4
- require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
3
+ require_relative '../../lib/robust_excel_ole'
4
+ require_relative '../../spec/helpers/create_temporary_dir'
5
5
  require "fileutils"
6
6
 
7
7
  include RobustExcelOle
@@ -14,36 +14,37 @@ another_simple_file = dir + 'another_workbook.xls'
14
14
  Excel.kill_all
15
15
 
16
16
  # open a workbook
17
+ puts "open a workbook"
17
18
  book = Workbook.open(simple_file)
19
+ puts "make it visible"
20
+ book.visible = true
18
21
  puts "book: #{book}"
19
22
  # open a workbook in a new Excel instance
20
- book2 = Workbook.open(another_simple_file, :default => {:excel => :new})
23
+ puts "open the workbook in a new Excel instance and make it visible"
24
+ book2 = Workbook.open(another_simple_file, :default => {:excel => :new}, :visible => true)
21
25
  puts "book2: #{book2}"
22
- # open the workbook in a separate, reserved Excel instance.
23
- book3 = Workbook.open(different_simple_file, :default => {:excel => :reserved_new})
24
- puts "book3: #{book3}"
25
- # open the workbook in a new Excel instance and make it visible
26
- book4 = Workbook.open(simple_file, :force => {:excel => :new}, :visible => true)
27
- puts "book4: #{book4}"
26
+ puts "create a new Excel"
27
+ excel1 = Excel.create(:visible => true)
28
28
  # open the workbook in a given Excel instance
29
+ puts "open the workbook in a given Excel instance"
29
30
  excel1 = book.excel
30
- book5 = Workbook.open(another_simple_file, :force => {:excel => excel1})
31
- puts "book5: #{book5}"
31
+ book3 = Workbook.open(another_simple_file, :force => {:excel => excel1})
32
+ puts "book3: #{book3}"
32
33
  # close a workbook
34
+ puts "close the first workbook"
33
35
  book.close
34
- puts "close book -> book: #{book}"
35
36
  # reopen the workbook
36
- book6 = book.reopen
37
- puts "reopened book: book6: #{book6}"
37
+ puts "reopen the workbook"
38
+ book4 = book.reopen
39
+ puts "book4: #{book4}"
38
40
  # unobtrusively opening a workbook
41
+ puts "unobtrusively opening the workbook"
39
42
  Workbook.unobtrusively(simple_file) do |book|
40
43
  sheet = book.sheet(1)
41
44
  sheet[1,1] = "c"
42
45
  end
43
- book6.close
44
- book5.close
45
46
  book4.close
46
47
  book3.close
47
48
  book2.close
48
- Excel.close_all
49
+ Excel.kill_all
49
50
 
@@ -1,7 +1,7 @@
1
1
  # introducing example example_range.rb
2
2
 
3
- require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
4
- require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
3
+ require_relative '../../lib/robust_excel_ole'
4
+ require_relative '../../spec/helpers/create_temporary_dir'
5
5
  require "fileutils"
6
6
 
7
7
  include RobustExcelOle
@@ -13,14 +13,17 @@ simple_file2 = dir + 'workbook.xls'
13
13
  Excel.kill_all
14
14
 
15
15
  # opening a workbook
16
+ puts "opening a workbook:"
16
17
  book = Workbook.open(simple_file, :visible => true)
17
18
  # accessing the 1st worksheet of this workbook
19
+ puts "accessing 1st worksheet"
18
20
  sheet = book.sheet(1)
19
21
  # accessing a range consisting of one cell
20
22
  range = sheet.range([1,2])
21
23
  range2 = sheet.range("B1")
22
- puts "range: #{range.Value}"
23
- puts "range2: #{range2.Value}"
24
+ puts "cell [1,2]: #{range.Value}"
25
+ puts "B1: #{range2.Value}"
26
+ puts "the ranges are identical"
24
27
  # the ranges are identical
25
28
  # putting the values of the range
26
29
  puts "range.values: #{range.values}"
@@ -29,39 +32,49 @@ range3 = sheet.range([1..3,1..4])
29
32
  range4 = sheet.range([1..3,"A".."D"])
30
33
  # accessing the same range given the left top and the right bottum corner
31
34
  range5 = sheet.range(["A1:D3"])
32
- puts "range3: #{range3.Value}"
33
- puts "range4: #{range4.Value}"
34
- puts "range5: #{range5.Value}"
35
- # the ranges are identival
35
+ puts 'range([1..3,1..4]): #{range3.Value}'
36
+ puts 'range([1..3,"A".."D"]): #{range4.Value}'
37
+ puts 'range(["A1:D3"]): #{range5.Value}'
38
+ puts "the ranges are identical"
39
+ # the ranges are identical
36
40
  # putting the values if the range
37
- puts "range3.values: #{range3.values}"
41
+ puts "range([1..3,1..4]).values: #{range3.values}"
38
42
  # copying a range
43
+ puts "copying the range[1..3,1..4] to cell [6,2]"
39
44
  range3.copy([6,2])
40
45
  range6 = sheet.range([6..9,2..5])
41
- puts "range3.Value: #{range3.Value}"
42
- puts "range6.Value: #{range6.Value}"
46
+ puts "range([1..3,1..4]).Value: #{range3.Value}"
47
+ puts "range([6..9,2..5]).Value: #{range6.Value}"
43
48
  # copying a range into another worksheet in another workbook of another Excel instance
49
+ puts "copying a range into another worksheet in another workbook of another Excel instance"
50
+ puts "opening a new workbook in a new Excel instance"
44
51
  book2 = Workbook.open(simple_file2, :excel => :new, :visible => true)
45
52
  range3.copy([5,8], book2.sheet(3))
46
53
  range7 = book2.sheet(3).range([5..8,8..11])
47
- puts "range3.Value: #{range3.Value}"
48
- puts "range7.Value: #{range7.Value}"
54
+ puts "range([1..3,1..4]).Value: #{range3.Value}"
55
+ puts "new_book.sheet(3).range([5..8,8..11]).Value: #{range7.Value}"
49
56
  # adding a defined name referring to a range consisting of the first cell
57
+ puts "adding a defined name 'name' referring to a range consisting of the 1st cell:"
50
58
  book.add_name("name",[1,1])
51
59
  # adding a defined name referring to a rectangular range
60
+ puts "adding a defined name 'name' referring to a rectangular range [1..2,3..4]:"
52
61
  book.add_name("name",[1..2,3..4])
53
62
  # assigning a value to that range
63
+ puts "assigning a value to that range:"
54
64
  book["name"] = [["foo", "bar"],[1.0, nil]]
55
65
  # reading the value of that range
56
66
  value = book["name"]
57
- puts "value: #{value}"
67
+ puts 'value of range "name": #{value}'
58
68
  # renaming a range
69
+ puts 'renaming range from "name" to "new_name"'
59
70
  book.rename_range("name", "new_name")
60
71
  # deleting the name of a range
72
+ puts 'deleting name "new_name"'
61
73
  book.delete_name("new_name")
62
74
  # reading the value of a cell
63
75
  cell_value = sheet[1,1].Value
64
- puts "cell_value: #{cell_value}"
76
+ puts "value of 1st cell: #{cell_value}"
65
77
  # writing the value of a cell
78
+ puts 'writing the value "bar" into 1st cell'
66
79
  sheet[1,1] = "bar"
67
- Excel.close_all(:if_unsaved => :forget)
80
+ Excel.kill_all
@@ -1,8 +1,8 @@
1
1
  # example_access_sheets_and_cells.rb:
2
2
  # access sheets, print cells, rows, and columns of a sheet
3
3
 
4
- require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
5
- require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
4
+ require_relative '../../lib/robust_excel_ole'
5
+ require_relative '../../spec/helpers/create_temporary_dir'
6
6
  require "fileutils"
7
7
 
8
8
  include RobustExcelOle
@@ -13,7 +13,7 @@ begin
13
13
  simple_file = dir + 'workbook.xls'
14
14
  simple_save_file = dir + 'workbook_save.xls'
15
15
  File.delete simple_save_file rescue nil
16
- book = Workbook.open(simple_file) # open a book
16
+ book = Workbook.open(simple_file, :visible => true) # open a book
17
17
  sheet = book.sheet(1) # access a sheet via integer
18
18
  cell = sheet[1,1] # access the first cell
19
19
  puts "1st cell: #{cell.Value}" # put the value of the first cell
@@ -34,7 +34,7 @@ begin
34
34
  when :each_row then "row"
35
35
  when :each_column then "column"
36
36
  end
37
- puts "#{item_name} #{i}: #{item.Value}" # put values of the item of the sheet
37
+ puts "#{item_name} #{i}: #{item.Value}" # put values of the item of the worksheet
38
38
  end
39
39
  end
40
40
 
@@ -42,11 +42,12 @@ begin
42
42
  sheet_enum[:each_row] # put rows
43
43
  sheet_enum[:each_column] # put columns
44
44
 
45
- book.save # save the book
46
- book.close # close the book
45
+ book.save # save the workbook
46
+ book.close # close the workbook
47
47
 
48
48
  ensure
49
- Excel.close_all(:if_unsaved => :forget)
49
+ #Excel.close_all(:if_unsaved => :forget)
50
+ Excel.kill_all
50
51
  rm_tmp(dir)
51
52
  end
52
53
 
@@ -3,8 +3,8 @@
3
3
  # the contents of each cell is copied
4
4
  # the new workbook's name is extended by the suffix "_named"
5
5
 
6
- require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
7
- require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
6
+ require_relative '../../lib/robust_excel_ole'
7
+ require_relative '../../spec/helpers/create_temporary_dir'
8
8
  require "fileutils"
9
9
 
10
10
  include RobustExcelOle
@@ -17,15 +17,13 @@ begin
17
17
  filename = dir + "/" + workbook_name
18
18
  puts "filename: #{filename}"
19
19
 
20
- Excel.close_all if_unsaved: :forget
20
+ #Excel.close_all if_unsaved: :forget
21
+ Excel.kill_all
21
22
  book = Workbook.new filename, if_absent: :create, visible: true, if_unsaved: :accept
22
23
  sheet = book.sheet(1)
23
24
  puts "book: #{book}"
24
25
  puts "sheet: #{sheet}"
25
26
 
26
- # book.Names.Add("µ", RefersToR1C1Local:"=Z")
27
- # book.Names.Add("µ_1", RefersToR1C1Local:"=Z(-1)")
28
-
29
27
  def define_columns sheet, columns_ids
30
28
  puts "define_columns:"
31
29
  first_column = sheet.range("A")
@@ -43,8 +41,6 @@ begin
43
41
  puts "sheet[1,colnr]: #{sheet[1,colnr].Value}"
44
42
  sheet.add_name(nam,[nil,colnr])
45
43
  puts "sheet.Range().Address: #{sheet.Range(nam).Address}"
46
- #sheet.add_name(nam,"A")
47
- # blatt.Names.Add(Name: nam, RefersTo: "="+erste_spalte.Offset(0,idx).Address)
48
44
  end
49
45
  end
50
46
 
@@ -1,8 +1,8 @@
1
1
  # example_adding_sheets.rb:
2
2
  # adding new and copied at various positions with various sheet names
3
3
 
4
- require File.expand_path('../../lib/robust_excel_ole', File.dirname(__FILE__))
5
- require File.join(File.dirname(File.expand_path(__FILE__)), '../../spec/helpers/create_temporary_dir')
4
+ require_relative '../../lib/robust_excel_ole'
5
+ require_relative '../../spec/helpers/create_temporary_dir'
6
6
  require "fileutils"
7
7
 
8
8
  include RobustExcelOle
@@ -13,11 +13,11 @@ begin
13
13
  simple_file = dir + 'workbook.xls'
14
14
  simple_save_file = dir + 'workbook_save.xls'
15
15
  File.delete simple_save_file rescue nil
16
- @book = Workbook.open(simple_file) # open a book
16
+ @book = Workbook.open(simple_file, :visible => true) # open a workbook
17
17
 
18
18
  def show_sheets
19
- @book.each do |sheet| # access each sheet
20
- puts "sheet name: #{sheet.name}" # put the sheet name
19
+ @book.each do |sheet| # access each worksheet
20
+ puts "sheet name: #{sheet.name}" # put the worksheet name
21
21
  end
22
22
  end
23
23
 
@@ -63,7 +63,8 @@ begin
63
63
  @book.close(:if_unsaved => :forget) # close the book without saving it
64
64
 
65
65
  ensure
66
- Excel.close_all(:if_unsaved => :forget)
66
+ Excel.kill_all
67
+ #Excel.close_all(:if_unsaved => :forget)
67
68
  rm_tmp(dir)
68
69
  end
69
70