robust_excel_ole 1.11 → 1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +11 -0
- data/README.rdoc +20 -8
- data/docs/README_open.rdoc +1 -0
- data/docs/README_ranges.rdoc +5 -11
- data/examples/{introducing_examples/example_introducing.rb → introductory_examples/example_introductory.rb} +10 -2
- data/examples/{introducing_examples → introductory_examples}/example_open.rb +18 -17
- data/examples/{introducing_examples → introductory_examples}/example_range.rb +29 -16
- data/examples/modifying_sheets/example_access_sheets_and_cells.rb +8 -7
- data/examples/modifying_sheets/example_add_names.rb +4 -8
- data/examples/modifying_sheets/example_adding_sheets.rb +7 -6
- data/examples/modifying_sheets/example_concating.rb +2 -2
- data/examples/modifying_sheets/example_copying.rb +3 -3
- data/examples/modifying_sheets/example_expanding.rb +2 -2
- data/examples/modifying_sheets/example_naming.rb +2 -2
- data/examples/modifying_sheets/example_ranges.rb +4 -4
- data/examples/modifying_sheets/example_saving.rb +3 -3
- data/examples/open_save_close/example_control_to_excel.rb +10 -11
- data/examples/open_save_close/example_default_excel.rb +13 -14
- data/examples/open_save_close/example_force_excel.rb +9 -10
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +7 -7
- data/examples/open_save_close/example_if_obstructed_forget.rb +5 -5
- data/examples/open_save_close/example_if_obstructed_save.rb +7 -7
- data/examples/open_save_close/example_if_unsaved_accept.rb +13 -13
- data/examples/open_save_close/example_if_unsaved_forget.rb +9 -10
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +9 -10
- data/examples/open_save_close/example_read_only.rb +6 -6
- data/examples/open_save_close/example_rename_cells.rb +4 -5
- data/examples/open_save_close/example_reuse.rb +6 -6
- data/examples/open_save_close/example_simple.rb +5 -5
- data/examples/open_save_close/example_unobtrusively.rb +4 -4
- data/lib/robust_excel_ole/address.rb +0 -4
- data/lib/robust_excel_ole/bookstore.rb +4 -28
- data/lib/robust_excel_ole/excel.rb +17 -22
- data/lib/robust_excel_ole/general.rb +11 -18
- data/lib/robust_excel_ole/range_owners.rb +17 -27
- data/lib/robust_excel_ole/reo_common.rb +7 -3
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +178 -180
- data/lib/robust_excel_ole/worksheet.rb +7 -4
- data/robust_excel_ole.gemspec +6 -4
- data/spec/bookstore_spec.rb +38 -34
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +89 -44
- data/spec/general_spec.rb +1 -0
- data/spec/range_spec.rb +7 -4
- data/spec/workbook_specs/workbook_close_spec.rb +2 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +34 -18
- data/spec/workbook_specs/workbook_open_spec.rb +112 -71
- data/spec/workbook_specs/workbook_save_spec.rb +173 -5
- data/spec/workbook_specs/workbook_sheet_spec.rb +6 -42
- data/spec/workbook_specs/workbook_unobtr_spec.rb +9 -246
- data/spec/worksheet_spec.rb +21 -5
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b568d18d573ee255b9c3601e983c3d7b1ff062fe50b97dc10bc1e9a79efb1556
|
4
|
+
data.tar.gz: 3f87e8db112deb8e414f77b2d5756158a79b135413ba6a1116d7b7abf68c710f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
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+.
|
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.
|
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
|
|
data/docs/README_open.rdoc
CHANGED
@@ -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
|
|
data/docs/README_ranges.rdoc
CHANGED
@@ -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
|
310
|
-
|
311
|
-
book.
|
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"
|
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
|
-
|
4
|
-
|
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
|
-
|
4
|
-
|
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
|
-
|
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
|
-
|
23
|
-
|
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
|
-
|
31
|
-
puts "
|
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
|
-
|
37
|
-
|
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.
|
49
|
+
Excel.kill_all
|
49
50
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# introducing example example_range.rb
|
2
2
|
|
3
|
-
|
4
|
-
|
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 "
|
23
|
-
puts "
|
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
|
33
|
-
puts "
|
34
|
-
puts "
|
35
|
-
|
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 "
|
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 "
|
42
|
-
puts "
|
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 "
|
48
|
-
puts "
|
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 "
|
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 "
|
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.
|
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
|
-
|
5
|
-
|
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
|
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
|
46
|
-
book.close # close the
|
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
|
-
|
7
|
-
|
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
|
-
|
5
|
-
|
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
|
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
|
20
|
-
puts "sheet name: #{sheet.name}" # put the
|
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.
|
66
|
+
Excel.kill_all
|
67
|
+
#Excel.close_all(:if_unsaved => :forget)
|
67
68
|
rm_tmp(dir)
|
68
69
|
end
|
69
70
|
|