robust_excel_ole 1.27 → 1.32
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 +36 -2
- data/README.rdoc +121 -19
- data/___dummy_workbook.xls +0 -0
- data/benchmarking/creek_example.rb +1 -1
- data/benchmarking/reo_example.rb +1 -1
- data/benchmarking/reo_example1.rb +1 -1
- data/benchmarking/reo_example2.rb +1 -1
- data/benchmarking/roo_example.rb +1 -1
- data/benchmarking/simple_xlsx_reader_example.rb +1 -1
- data/benchmarking/spreadsheet_example.rb +1 -1
- data/bin/jreo +19 -0
- data/bin/reo +19 -0
- data/docs/README_excel.rdoc +16 -24
- data/docs/README_listobjects.rdoc +176 -0
- data/docs/README_open.rdoc +20 -16
- data/docs/README_ranges.rdoc +72 -55
- data/docs/README_save_close.rdoc +3 -3
- data/docs/README_sheet.rdoc +19 -20
- data/examples/example_ruby_library.rb +2 -2
- data/examples/introductory_examples/example_open.rb +11 -0
- data/examples/introductory_examples/example_range.rb +2 -2
- data/examples/modifying_sheets/example_access_sheets_and_cells.rb +6 -6
- data/examples/modifying_sheets/example_add_names.rb +1 -1
- data/examples/modifying_sheets/example_concating.rb +1 -1
- data/examples/modifying_sheets/example_copying.rb +2 -2
- data/examples/modifying_sheets/example_listobjects.rb +86 -0
- data/examples/modifying_sheets/example_naming.rb +1 -1
- data/examples/modifying_sheets/example_ranges.rb +1 -1
- data/examples/open_save_close/example_control_to_excel.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_save.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +3 -3
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -4
- data/examples/open_save_close/example_read_only.rb +1 -1
- data/examples/open_save_close/example_simple.rb +1 -1
- data/examples/open_save_close/example_unobtrusively.rb +3 -3
- data/lib/robust_excel_ole.rb +19 -16
- data/lib/robust_excel_ole/address_tool.rb +54 -44
- data/lib/robust_excel_ole/base.rb +9 -6
- data/lib/robust_excel_ole/bookstore.rb +3 -17
- data/lib/robust_excel_ole/cell.rb +17 -22
- data/lib/robust_excel_ole/cygwin.rb +2 -0
- data/lib/robust_excel_ole/excel.rb +136 -201
- data/lib/robust_excel_ole/general.rb +249 -238
- data/lib/robust_excel_ole/list_object.rb +186 -210
- data/lib/robust_excel_ole/list_row.rb +155 -0
- data/lib/robust_excel_ole/range.rb +130 -94
- data/lib/robust_excel_ole/range_owners.rb +54 -135
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +230 -196
- data/lib/robust_excel_ole/worksheet.rb +254 -133
- data/lib/spec_helper.rb +1 -1
- data/robust_excel_ole.gemspec +4 -3
- data/spec/address_tool_spec.rb +2 -2
- data/spec/base_spec.rb +19 -17
- data/spec/bookstore_spec.rb +3 -4
- data/spec/cell_spec.rb +10 -10
- data/spec/cygwin_spec.rb +1 -1
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +133 -86
- data/spec/general_spec.rb +79 -18
- data/spec/list_object_spec.rb +259 -81
- data/spec/list_row_spec.rb +218 -0
- data/spec/range_spec.rb +75 -41
- data/spec/spec_helper.rb +16 -2
- data/spec/workbook_spec.rb +87 -46
- data/spec/workbook_specs/workbook_all_spec.rb +9 -28
- data/spec/workbook_specs/workbook_close_spec.rb +1 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +52 -45
- data/spec/workbook_specs/workbook_open_spec.rb +103 -50
- data/spec/workbook_specs/workbook_save_spec.rb +22 -23
- data/spec/workbook_specs/workbook_sheet_spec.rb +4 -4
- data/spec/workbook_specs/workbook_subclass_spec.rb +1 -1
- data/spec/workbook_specs/workbook_unobtr_spec.rb +553 -395
- data/spec/worksheet_spec.rb +544 -308
- metadata +38 -3
- data/lib/reo_console.rb +0 -42
data/docs/README_save_close.rdoc
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
Imagine, you have opened a workbook with
|
8
8
|
|
9
|
-
workbook = Workbook.open('spec/data/workbook.xls', :
|
9
|
+
workbook = Workbook.open('spec/data/workbook.xls', visible: true)
|
10
10
|
|
11
11
|
and have modified it.
|
12
12
|
|
@@ -33,13 +33,13 @@ If a workbook with the file name already exists, then
|
|
33
33
|
|
34
34
|
For example, you want to save a workbook and overwrite the file if it exists before, then use
|
35
35
|
|
36
|
-
workbook.save_as('another_workbook.xls', :
|
36
|
+
workbook.save_as('another_workbook.xls', if_exists: :overwrite)
|
37
37
|
|
38
38
|
If a workbook blocks the workbook that should be saved, then the former one can be saved and closed before.
|
39
39
|
|
40
40
|
workbook = Workbook.open('spec/data/workbook.xls')
|
41
41
|
workbook2 = Workbook.open('spec/data/another_workbook.xls')
|
42
|
-
workbook2.save_as('dir/workbook.xls', :
|
42
|
+
workbook2.save_as('dir/workbook.xls', if_exists: :overwrite, if_obstructed: :save)
|
43
43
|
|
44
44
|
=== Closing a workbook.
|
45
45
|
|
data/docs/README_sheet.rdoc
CHANGED
@@ -6,7 +6,7 @@ Worksheets are represented by Worksheet objects.
|
|
6
6
|
|
7
7
|
Assume you have opened a workbook
|
8
8
|
|
9
|
-
workbook = Workbook.open('spec/data/workbook.xls', :
|
9
|
+
workbook = Workbook.open('spec/data/workbook.xls', visible: true)
|
10
10
|
|
11
11
|
=== Accessing a worksheet.
|
12
12
|
|
@@ -53,11 +53,11 @@ You can add (append) an empty worksheet using
|
|
53
53
|
|
54
54
|
Additionally you can name it.
|
55
55
|
|
56
|
-
workbook.add_empty_sheet(:
|
56
|
+
workbook.add_empty_sheet(as: 'sheet_name')
|
57
57
|
|
58
58
|
You can specify the position of the added empty worksheet.
|
59
59
|
|
60
|
-
workbook.add_empty_sheet(:
|
60
|
+
workbook.add_empty_sheet(as: 'new_name', before: another_sheet)
|
61
61
|
|
62
62
|
You can copy a worksheet and add it.
|
63
63
|
|
@@ -65,44 +65,43 @@ You can copy a worksheet and add it.
|
|
65
65
|
|
66
66
|
Additionally you can specify a name and a position.
|
67
67
|
|
68
|
-
workbook.copy_sheet(sheet, :
|
68
|
+
workbook.copy_sheet(sheet, as: 'new_name', after: another_sheet)
|
69
69
|
|
70
70
|
If you want to copy a worksheet, if a worksheet +sheet+ is given, and add an empty worksheet, if no worksheet is given, then use
|
71
71
|
|
72
72
|
workbook.add_or_copy_sheet
|
73
73
|
|
74
|
-
workbook.add_or_copy_sheet(sheet, :
|
74
|
+
workbook.add_or_copy_sheet(sheet, as: 'new_name', after: another_sheet)
|
75
75
|
|
76
76
|
Note, that running in jruby, due to some restrictions of jruby, there is a workaround when adding or copy a worksheet at the end (appending): the last worksheet is being copied and deleted afterwards, in order to serve as a dummy worksheet. This may cause a different behaviour.
|
77
77
|
|
78
78
|
=== Accessing rows and columns
|
79
79
|
|
80
|
-
The methods Worksheet#each
|
80
|
+
The methods Worksheet#each returns an enumerator traversing the rows (more specific: the row values) in the used range of the worksheet. The methods +each_row+ and +each_column traverse the values in the rows and columns, respectively, using an optional offset.
|
81
|
+
The methods +each_cell+ enables to access the values of each cell.
|
81
82
|
|
82
|
-
worksheet.each do |
|
83
|
-
# do something with
|
84
|
-
# read every row, every column
|
83
|
+
worksheet.each do |row_values|
|
84
|
+
# do something with the row_values
|
85
85
|
end
|
86
86
|
|
87
|
-
worksheet.each_row do |row|
|
88
|
-
# do something with row
|
87
|
+
worksheet.each_row(2) do |row|
|
88
|
+
# do something with row beginning with 2nd row
|
89
89
|
end
|
90
90
|
|
91
|
-
worksheet.each_column do |column|
|
92
|
-
# do something with column
|
91
|
+
worksheet.each_column(3) do |column|
|
92
|
+
# do something with column beginning with 3rd column
|
93
93
|
end
|
94
94
|
|
95
|
-
|
95
|
+
worksheet.each_cell do |cell|
|
96
|
+
# do something with cell
|
97
|
+
# read every row, every column
|
98
|
+
end
|
99
|
+
|
100
|
+
The method Worksheet#values yields a 2-dimensional array that contains the values in each row, e.g.
|
96
101
|
|
97
102
|
worksheet.values
|
98
103
|
=> [["foo", "workbook", "sheet1"], ["foo", nil, "foobaaa"], ["matz", "is", "nice"]]
|
99
104
|
|
100
|
-
The method Worksheet#each_rowvalue enables to access the values of each row.
|
101
|
-
|
102
|
-
worksheet.each_rowvalue do |row_values|
|
103
|
-
# do something with the row_values
|
104
|
-
end
|
105
|
-
|
106
105
|
You access a range of a row by giving the number of the row, and optionally, the range of the cell numbers.
|
107
106
|
|
108
107
|
worksheet.row_range(1) # => first row
|
@@ -14,8 +14,8 @@ workbook.each do |worksheet|
|
|
14
14
|
puts "Reading: #{worksheet.name}"
|
15
15
|
num_rows = 0
|
16
16
|
|
17
|
-
worksheet.each do |
|
18
|
-
|
17
|
+
worksheet.each do |row_values|
|
18
|
+
a = row_values.map{ |cell| cell }
|
19
19
|
num_rows += 1
|
20
20
|
|
21
21
|
# uncomment to print out row values
|
@@ -18,7 +18,18 @@ puts "open a workbook"
|
|
18
18
|
book = Workbook.open(simple_file)
|
19
19
|
puts "make it visible"
|
20
20
|
book.visible = true
|
21
|
+
|
22
|
+
ole_workbook = book.ole_workbook
|
23
|
+
puts "ole_workbook: #{ole_workbook}"
|
24
|
+
sheet = ole_workbook.sheet(1)
|
25
|
+
puts "sheet: #{sheet}"
|
26
|
+
|
27
|
+
using ToReoRefinement
|
21
28
|
puts "book: #{book}"
|
29
|
+
ole_workbook = book.ole_workbook
|
30
|
+
puts "ole_workbook: #{ole_workbook.inspect}"
|
31
|
+
upliftet_ole_workbook = ole_workbook.to_reo
|
32
|
+
puts "upliftet_ole_workbook: #{upliftet_ole_workbook.inspect}"
|
22
33
|
# open a workbook in a new Excel instance
|
23
34
|
puts "open the workbook in a new Excel instance and make it visible"
|
24
35
|
book2 = Workbook.open(another_simple_file, :default => {:excel => :new}, :visible => true)
|
@@ -67,12 +67,12 @@ value = book["name"]
|
|
67
67
|
puts 'value of range "name": #{value}'
|
68
68
|
# renaming a range
|
69
69
|
puts 'renaming range from "name" to "new_name"'
|
70
|
-
book.
|
70
|
+
book.rename_name("name", "new_name")
|
71
71
|
# deleting the name of a range
|
72
72
|
puts 'deleting name "new_name"'
|
73
73
|
book.delete_name("new_name")
|
74
74
|
# reading the value of a cell
|
75
|
-
cell_value = sheet[1,1]
|
75
|
+
cell_value = sheet[1,1]
|
76
76
|
puts "value of 1st cell: #{cell_value}"
|
77
77
|
# writing the value of a cell
|
78
78
|
puts 'writing the value "bar" into 1st cell'
|
@@ -15,22 +15,22 @@ begin
|
|
15
15
|
File.delete simple_save_file rescue nil
|
16
16
|
book = Workbook.open(simple_file, :visible => true) # open a book
|
17
17
|
sheet = book.sheet(1) # access a sheet via integer
|
18
|
-
cell = sheet[1,1] # access the first cell
|
18
|
+
cell = sheet.range([1,1]) # access the first cell
|
19
19
|
puts "1st cell: #{cell.Value}" # put the value of the first cell
|
20
20
|
sheet[1,1] = "complex" # write a value into a cell
|
21
|
-
puts "new cell: #{sheet[1,1]
|
21
|
+
puts "new cell: #{sheet[1,1]}"
|
22
22
|
puts "all cells:"
|
23
|
-
sheet.
|
23
|
+
sheet.each_cell do |cell| # access all cells
|
24
24
|
puts "#{cell.Value}" # for each row: for every column: put the value of the cells
|
25
25
|
end
|
26
26
|
|
27
27
|
sheet_enum = proc do |enum_method| # put each cell, each row or each column
|
28
28
|
i = 0
|
29
29
|
sheet.send(enum_method) do |item|
|
30
|
-
i
|
30
|
+
i += 1
|
31
31
|
item_name =
|
32
32
|
case enum_method
|
33
|
-
when :
|
33
|
+
when :each_cell then "cell"
|
34
34
|
when :each_row then "row"
|
35
35
|
when :each_column then "column"
|
36
36
|
end
|
@@ -38,7 +38,7 @@ begin
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
sheet_enum[:
|
41
|
+
sheet_enum[:each_cell] # put cells
|
42
42
|
sheet_enum[:each_row] # put rows
|
43
43
|
sheet_enum[:each_column] # put columns
|
44
44
|
|
@@ -38,7 +38,7 @@ begin
|
|
38
38
|
colnr = idx+1
|
39
39
|
puts "colnr: #{colnr}"
|
40
40
|
sheet[1,colnr] = nam
|
41
|
-
puts "sheet[1,colnr]: #{sheet[1,colnr]
|
41
|
+
puts "sheet[1,colnr]: #{sheet[1,colnr]}"
|
42
42
|
sheet.add_name(nam,[nil,colnr])
|
43
43
|
puts "sheet.Range().Address: #{sheet.Range(nam).Address}"
|
44
44
|
end
|
@@ -26,13 +26,13 @@ begin
|
|
26
26
|
book.each do |sheet|
|
27
27
|
new_sheet = book.add_sheet
|
28
28
|
contains_named_cells = false
|
29
|
-
sheet.
|
29
|
+
sheet.each_cell do |cell|
|
30
30
|
full_name = cell.Name.Name rescue nil
|
31
31
|
if full_name
|
32
32
|
sheet_name, short_name = full_name.split("!")
|
33
33
|
cell_name = short_name ? short_name : sheet_name
|
34
34
|
contains_named_cells = true
|
35
|
-
new_sheet[cell.Row, cell.Column]
|
35
|
+
new_sheet[cell.Row, cell.Column] = cell.Value
|
36
36
|
new_sheet.add_name(cell_name, [cell.Row,cell.Column])
|
37
37
|
end
|
38
38
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# example_ranges.rb:
|
2
|
+
# access row and column ranges of a sheet.
|
3
|
+
|
4
|
+
require_relative '../../lib/robust_excel_ole'
|
5
|
+
require_relative '../../spec/helpers/create_temporary_dir'
|
6
|
+
require "fileutils"
|
7
|
+
|
8
|
+
include RobustExcelOle
|
9
|
+
|
10
|
+
using StringRefinement
|
11
|
+
|
12
|
+
Excel.close_all
|
13
|
+
begin
|
14
|
+
dir = create_tmpdir
|
15
|
+
table_file = dir + 'workbook_listobjects.xlsx'
|
16
|
+
book = Workbook.open(table_file, :visible => true) # open a workbook
|
17
|
+
sheet = book.sheet(3) # access a worksheet via the name
|
18
|
+
table = sheet.table(1) # access a list object (table)
|
19
|
+
|
20
|
+
puts "table: #{table}"
|
21
|
+
|
22
|
+
listrow1 = table[2] # access the second list row of the table
|
23
|
+
|
24
|
+
puts "listrow1: #{listrow1}"
|
25
|
+
|
26
|
+
values1 = listrow1.values # access the values of this listrow
|
27
|
+
puts "values: #{values1}"
|
28
|
+
|
29
|
+
listrow2 = table[{"Number" => 3, "Person" => "Angel"}] # acess a list row via a given key hash
|
30
|
+
|
31
|
+
puts "listrow2: #{listrow2}"
|
32
|
+
|
33
|
+
values2 = listrow2.values
|
34
|
+
puts "values: #{values2}"
|
35
|
+
|
36
|
+
listrows3 = table[{"Number" => 3}, limit: 2] # access maximal 2 listrows matching the key
|
37
|
+
|
38
|
+
puts "listrows3: #{listrows3}"
|
39
|
+
puts "values:"
|
40
|
+
listrows3.map{|l| puts l.values}
|
41
|
+
|
42
|
+
puts "deleting the values of the second row" # deleting the contents of the second row
|
43
|
+
table.delete_row_values(2)
|
44
|
+
|
45
|
+
puts "deleting empty rows"
|
46
|
+
table.delete_empty_rows # deleting empty rows
|
47
|
+
|
48
|
+
puts "sorting table:"
|
49
|
+
table.sort("Number") # sort table
|
50
|
+
|
51
|
+
puts "find all cells:" # find all cells containing a given value
|
52
|
+
cells = table.find_cells(40)
|
53
|
+
puts "cells: #{cells}"
|
54
|
+
|
55
|
+
# create a new table
|
56
|
+
table2 = Table.new(sheet, "table_name", [20,1], 3, ["Verkäufer", "Straße", "area in m²"])
|
57
|
+
puts "table2: #{table2}"
|
58
|
+
|
59
|
+
table_row1 = table[1]
|
60
|
+
puts "list_row1 of second table: #{table_row1}"
|
61
|
+
|
62
|
+
table_row1.verkaeufer = "John"
|
63
|
+
value3 = table_row1.verkaeufer
|
64
|
+
puts "value of verkaeufer: #{value3}"
|
65
|
+
|
66
|
+
value4 = table_row1.Verkaeufer
|
67
|
+
puts "value of verkaeufer: #{value4}"
|
68
|
+
|
69
|
+
table_row1.strasse = 42
|
70
|
+
value5 = table_row1.strasse
|
71
|
+
puts "value of strasse: #{value5}"
|
72
|
+
|
73
|
+
table_row1.area_in_m2 = 400
|
74
|
+
value6 = table_row1.area_in_m2
|
75
|
+
puts "value of area in m2: #{value6}"
|
76
|
+
|
77
|
+
sleep 5
|
78
|
+
|
79
|
+
book.close(:if_unsaved => :forget)
|
80
|
+
|
81
|
+
ensure
|
82
|
+
Excel.close_all
|
83
|
+
rm_tmp(dir)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
@@ -27,7 +27,7 @@ begin
|
|
27
27
|
|
28
28
|
Workbook.unobtrusively(extended_file_name) do |book|
|
29
29
|
book.each do |sheet|
|
30
|
-
sheet.
|
30
|
+
sheet.each_cell do |cell_orig|
|
31
31
|
contents = cell_orig.Value
|
32
32
|
sheet.add_name(contents, [cell_orig.Row, cell_orig.Column]) if contents && contents.is_a?(String)
|
33
33
|
end
|
@@ -14,7 +14,7 @@ begin
|
|
14
14
|
book = Workbook.open(file_name, :visible => true) # open a book
|
15
15
|
sleep 1
|
16
16
|
sheet = book.sheet(1) # access a worksheet
|
17
|
-
sheet[1,1] = sheet[1,1]
|
17
|
+
sheet[1,1] = sheet[1,1] == "simple" ? "complex" : "simple" # change a cell
|
18
18
|
sleep 1
|
19
19
|
begin
|
20
20
|
new_book = Workbook.open(file_name, :visible => true, :if_unsaved => :alert) # open another workbook with the same file name
|
@@ -15,7 +15,7 @@ begin
|
|
15
15
|
book = Workbook.open(file_name, :visible => true) # open a workbook, make Excel visible
|
16
16
|
sleep 1
|
17
17
|
sheet = book.sheet(1)
|
18
|
-
first_cell = sheet[1,1]
|
18
|
+
first_cell = sheet[1,1] # access a worksheet
|
19
19
|
sheet[1,1] = first_cell == "simple" ? "complex" : "simple" # change a cell
|
20
20
|
sleep 1
|
21
21
|
begin
|
@@ -15,7 +15,7 @@ begin
|
|
15
15
|
book = Workbook.open(file_name, :visible => true) # open a workbook, make Excel visible
|
16
16
|
sleep 1
|
17
17
|
sheet = book.sheet(1)
|
18
|
-
first_cell = sheet[1,1]
|
18
|
+
first_cell = sheet[1,1] # access a worksheet
|
19
19
|
sheet[1,1] = first_cell == "simple" ? "complex" : "simple" # change a cell
|
20
20
|
sleep 1
|
21
21
|
new_book = Workbook.open(other_file_name, :if_obstructed => :save) # open a workbook with the same file name in a different path
|
@@ -23,11 +23,11 @@ begin
|
|
23
23
|
old_book = Workbook.open(file_name, :if_obstructed => :forget ,:visible => true) # open the old book
|
24
24
|
sleep 1
|
25
25
|
old_sheet = old_book.sheet(1)
|
26
|
-
old_first_cell = old_sheet[1,1]
|
26
|
+
old_first_cell = old_sheet[1,1]
|
27
27
|
puts "the old book was saved" unless old_first_cell == first_cell
|
28
28
|
new_book.close # close the workbooks
|
29
29
|
old_book.close
|
30
30
|
ensure
|
31
31
|
Excel.kill_all # close all workbooks, quit Excel application
|
32
|
-
rm_tmp(dir)
|
32
|
+
#rm_tmp(dir)
|
33
33
|
end
|
@@ -13,7 +13,7 @@ begin
|
|
13
13
|
file_name = dir + 'workbook.xls'
|
14
14
|
book = Workbook.open(file_name, :visible => true) # open a workbook
|
15
15
|
sheet = book.sheet(1) # access a worksheet
|
16
|
-
sheet[1,1] = sheet[1,1]
|
16
|
+
sheet[1,1] = sheet[1,1] == "simple" ? "complex" : "simple" # change a cell
|
17
17
|
begin
|
18
18
|
new_book = Workbook.open(file_name) # open another workbook with the same file name
|
19
19
|
rescue WorkbookNotSaved => msg # by default: raises an exception:
|
@@ -15,7 +15,7 @@ begin
|
|
15
15
|
puts "file_name: #{file_name}"
|
16
16
|
sleep 1
|
17
17
|
sheet = book.sheet(1) # access a worksheet
|
18
|
-
first_cell = sheet[1,1]
|
18
|
+
first_cell = sheet[1,1]
|
19
19
|
sheet[1,1] = first_cell == "simple" ? "complex" : "simple" # change a cell
|
20
20
|
sleep 1
|
21
21
|
puts "new_book: before"
|
@@ -24,11 +24,11 @@ begin
|
|
24
24
|
# and close the unsaved workbook without saving it
|
25
25
|
puts "new_book: after"
|
26
26
|
sheet_new_book = new_book.sheet(1)
|
27
|
-
if (not book.alive?) && new_book.alive? && sheet_new_book[1,1]
|
27
|
+
if (not book.alive?) && new_book.alive? && sheet_new_book[1,1] == first_cell then # check whether the unsaved workbook
|
28
28
|
puts "open with :if_unsaved => :forget : the unsaved book is closed and not saved." # is closed and was not saved
|
29
29
|
end
|
30
30
|
sleep 1
|
31
|
-
sheet_new_book[1,1] = sheet_new_book[1,1]
|
31
|
+
sheet_new_book[1,1] = sheet_new_book[1,1] == "simple" ? "complex" : "simple" # change a cell
|
32
32
|
# open another workbook in a new Excel application, and make Excel visible, leaving the unsaved workbook open
|
33
33
|
another_book = Workbook.open(file_name, :if_unsaved => :new_excel, :visible => true)
|
34
34
|
sleep 3 # leaving the unsaved workbook open
|
@@ -13,21 +13,21 @@ begin
|
|
13
13
|
file_name = dir + 'workbook.xls'
|
14
14
|
book = Workbook.open(file_name, :visible => true) # open a workbook
|
15
15
|
sheet = book.sheet(1) # access a worksheet
|
16
|
-
first_cell = sheet[1,1]
|
16
|
+
first_cell = sheet[1,1]
|
17
17
|
sheet[1,1] = first_cell == "simple" ? "complex" : "simple" # change a cell
|
18
18
|
sleep 1
|
19
19
|
new_book = Workbook.open(file_name, :if_unsaved => :new_excel, :visible => true) # open another workbook with the same file name in a new Excel
|
20
20
|
sheet_new_book = new_book.sheet(1)
|
21
|
-
if (not book.alive?) && new_book.alive? && sheet_new_book[1,1]
|
21
|
+
if (not book.alive?) && new_book.alive? && sheet_new_book[1,1] == first_cell then # check whether the unsaved workbook
|
22
22
|
puts "open with :if_unsaved => :forget : the unsaved book is closed and not saved." # is closed and was not saved
|
23
23
|
end
|
24
24
|
sleep 1
|
25
|
-
sheet_new_book[1,1] = sheet_new_book[1,1]
|
25
|
+
sheet_new_book[1,1] = sheet_new_book[1,1] == "simple" ? "complex" : "simple" # change a cell
|
26
26
|
# open another workbook in the running Excel application, and make Excel visible, closing the unsaved workbook
|
27
27
|
another_book = Workbook.open(file_name, :if_unsaved => :forget, :visible => true)
|
28
28
|
sleep 1
|
29
29
|
sheet_another_book = another_book.sheet(1)
|
30
|
-
sheet_another_book[1,1] = sheet_another_book[1,1]
|
30
|
+
sheet_another_book[1,1] = sheet_another_book[1,1] == "simple" ? "complex" : "simple" # change a cell
|
31
31
|
another_book.close(:if_unsaved => :forget ) # close the last workbook without saving it.
|
32
32
|
book.close(:if_unsaved => :save) # close the first workbook and save it before
|
33
33
|
ensure
|
@@ -14,7 +14,7 @@ begin
|
|
14
14
|
book = Workbook.open(file_name, :read_only => true, :visible => true) # open a workbook with read_only and make Excel visible
|
15
15
|
sheet = book.sheet(1) # access a worksheet
|
16
16
|
sleep 1
|
17
|
-
sheet[1,1] = sheet[1,1]
|
17
|
+
sheet[1,1] = sheet[1,1] == "simple" ? "complex" : "simple" # change a cell
|
18
18
|
sleep 1
|
19
19
|
begin
|
20
20
|
book.save # simple save.
|