robust_excel_ole 1.31 → 1.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +20 -1
- data/README.rdoc +118 -18
- data/___dummy_workbook.xls +0 -0
- data/benchmarking/creek_example.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/docs/README_excel.rdoc +16 -24
- data/docs/README_listobjects.rdoc +176 -0
- data/docs/README_open.rdoc +12 -12
- data/docs/README_ranges.rdoc +72 -55
- data/docs/README_save_close.rdoc +3 -3
- data/docs/README_sheet.rdoc +18 -13
- data/examples/example_ruby_library.rb +2 -2
- 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/address_tool.rb +54 -44
- data/lib/robust_excel_ole/base.rb +4 -6
- data/lib/robust_excel_ole/bookstore.rb +2 -16
- data/lib/robust_excel_ole/cell.rb +16 -21
- data/lib/robust_excel_ole/excel.rb +131 -186
- data/lib/robust_excel_ole/general.rb +82 -55
- data/lib/robust_excel_ole/list_object.rb +182 -109
- data/lib/robust_excel_ole/list_row.rb +65 -38
- data/lib/robust_excel_ole/range.rb +125 -93
- data/lib/robust_excel_ole/range_owners.rb +52 -66
- data/lib/robust_excel_ole/version.rb +1 -1
- data/lib/robust_excel_ole/workbook.rb +168 -176
- data/lib/robust_excel_ole/worksheet.rb +177 -141
- data/robust_excel_ole.gemspec +4 -3
- data/spec/bookstore_spec.rb +2 -3
- data/spec/cell_spec.rb +9 -9
- data/spec/data/more_data/workbook.xls +0 -0
- data/spec/excel_spec.rb +132 -85
- data/spec/general_spec.rb +47 -15
- data/spec/list_object_spec.rb +258 -145
- data/spec/list_row_spec.rb +218 -0
- data/spec/range_spec.rb +76 -29
- data/spec/spec_helper.rb +15 -1
- data/spec/workbook_spec.rb +75 -34
- data/spec/workbook_specs/workbook_all_spec.rb +2 -1
- data/spec/workbook_specs/workbook_misc_spec.rb +20 -13
- data/spec/workbook_specs/workbook_open_spec.rb +47 -45
- data/spec/workbook_specs/workbook_save_spec.rb +21 -22
- data/spec/workbook_specs/workbook_sheet_spec.rb +3 -3
- data/spec/workbook_specs/workbook_unobtr_spec.rb +303 -303
- data/spec/worksheet_spec.rb +522 -318
- metadata +37 -2
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,22 @@ require 'tmpdir'
|
|
4
4
|
require "fileutils"
|
5
5
|
require_relative '../lib/robust_excel_ole'
|
6
6
|
|
7
|
+
class Object
|
8
|
+
|
9
|
+
def encode_value
|
10
|
+
if self.respond_to?(:gsub)
|
11
|
+
encode('utf-8')
|
12
|
+
elsif self.respond_to?(:keys)
|
13
|
+
transform_values!{ |value| value.respond_to?(:gsub) ? value.encode('utf-8') : value}
|
14
|
+
elsif self.respond_to?(:pop)
|
15
|
+
map{|v| v.respond_to?(:gsub) ? v.encode('utf-8') : v}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
7
21
|
# @private
|
8
|
-
module RobustExcelOle::SpecHelpers
|
22
|
+
module RobustExcelOle::SpecHelpers
|
9
23
|
|
10
24
|
def create_tmpdir
|
11
25
|
tmpdir = Dir.mktmpdir
|
data/spec/workbook_spec.rb
CHANGED
@@ -111,7 +111,7 @@ describe Workbook do
|
|
111
111
|
book.should be_alive
|
112
112
|
book.should be_a Workbook
|
113
113
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
114
|
-
Excel.
|
114
|
+
Excel.instance_count.should == 1
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
@@ -467,10 +467,11 @@ describe Workbook do
|
|
467
467
|
@key_sender.puts "{right}{enter}"
|
468
468
|
@key_sender.puts "{right}{enter}"
|
469
469
|
@key_sender.puts "{right}{enter}"
|
470
|
-
expect{
|
470
|
+
#expect{
|
471
471
|
Workbook.open(@simple_file, :if_unsaved => :alert)
|
472
|
-
|
472
|
+
# }.to raise_error(UnexpectedREOError)
|
473
473
|
@book.should be_alive
|
474
|
+
@book.Saved.should be false
|
474
475
|
end
|
475
476
|
|
476
477
|
it "should open the new book and close the unsaved book, if user answers 'yes'" do
|
@@ -489,10 +490,11 @@ describe Workbook do
|
|
489
490
|
@key_sender.puts "{right}{enter}"
|
490
491
|
@key_sender.puts "{right}{enter}"
|
491
492
|
@key_sender.puts "{right}{enter}"
|
492
|
-
expect{
|
493
|
+
#expect{
|
493
494
|
Workbook.open(@simple_file, :if_unsaved => :excel)
|
494
|
-
}.to raise_error(UnexpectedREOError)
|
495
|
+
#}.to raise_error(UnexpectedREOError)
|
495
496
|
@book.should be_alive
|
497
|
+
@book.Saved.should be false
|
496
498
|
end
|
497
499
|
|
498
500
|
end
|
@@ -634,15 +636,15 @@ describe Workbook do
|
|
634
636
|
book.ReadOnly.should be true
|
635
637
|
book.should be_alive
|
636
638
|
sheet = book.sheet(1)
|
637
|
-
old_cell_value = sheet[1,1]
|
638
|
-
sheet[1,1] = sheet[1,1]
|
639
|
+
old_cell_value = sheet[1,1]
|
640
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
639
641
|
book.Saved.should be false
|
640
642
|
new_book = Workbook.open(@simple_file1, :read_only => false, :if_unsaved => :forget)
|
641
643
|
new_book.ReadOnly.should be false
|
642
644
|
new_book.should be_alive
|
643
645
|
book.should_not be_alive
|
644
646
|
new_sheet = new_book.sheet(1)
|
645
|
-
new_cell_value = new_sheet[1,1]
|
647
|
+
new_cell_value = new_sheet[1,1]
|
646
648
|
new_cell_value.should == old_cell_value
|
647
649
|
end
|
648
650
|
|
@@ -757,7 +759,7 @@ describe Workbook do
|
|
757
759
|
Workbook.unobtrusively(@simple_file) do |book|
|
758
760
|
book.should be_a Workbook
|
759
761
|
sheet = book.sheet(1)
|
760
|
-
sheet[1,1] = sheet[1,1]
|
762
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
761
763
|
book.should be_alive
|
762
764
|
book.Saved.should be false
|
763
765
|
end
|
@@ -838,18 +840,18 @@ describe Workbook do
|
|
838
840
|
@book.Saved.should be true
|
839
841
|
@book.should be_alive
|
840
842
|
sheet = @book.sheet(1)
|
841
|
-
old_cell_value = sheet[1,1]
|
843
|
+
old_cell_value = sheet[1,1]
|
842
844
|
unobtrusively_ok?
|
843
845
|
@book.Saved.should be true
|
844
846
|
@book.should be_alive
|
845
847
|
sheet = @book.sheet(1)
|
846
|
-
sheet[1,1].
|
848
|
+
sheet[1,1].should_not == old_cell_value
|
847
849
|
end
|
848
850
|
|
849
851
|
it "should let the unsaved book unsaved" do
|
850
852
|
sheet = @book.sheet(1)
|
851
|
-
sheet[1,1] = sheet[1,1]
|
852
|
-
old_cell_value = sheet[1,1]
|
853
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
854
|
+
old_cell_value = sheet[1,1]
|
853
855
|
@book.Saved.should be false
|
854
856
|
unobtrusively_ok?
|
855
857
|
@book.should be_alive
|
@@ -857,7 +859,7 @@ describe Workbook do
|
|
857
859
|
@book.close(:if_unsaved => :forget)
|
858
860
|
@book2 = Workbook.open(@simple_file1)
|
859
861
|
sheet2 = @book2.sheet(1)
|
860
|
-
sheet2[1,1].
|
862
|
+
sheet2[1,1].should_not == old_cell_value
|
861
863
|
end
|
862
864
|
end
|
863
865
|
|
@@ -873,21 +875,21 @@ describe Workbook do
|
|
873
875
|
|
874
876
|
it "should let the closed book closed by default" do
|
875
877
|
sheet = @book.sheet(1)
|
876
|
-
old_cell_value = sheet[1,1]
|
878
|
+
old_cell_value = sheet[1,1]
|
877
879
|
@book.close
|
878
880
|
@book.should_not be_alive
|
879
881
|
unobtrusively_ok?
|
880
882
|
@book.should_not be_alive
|
881
883
|
book2 = Workbook.open(@simple_file1)
|
882
884
|
sheet = book2.sheet(1)
|
883
|
-
sheet[1,1].
|
885
|
+
sheet[1,1].should_not == old_cell_value
|
884
886
|
end
|
885
887
|
|
886
888
|
# The bold reanimation of the @book
|
887
889
|
it "should use the excel of the book and keep open the book" do
|
888
890
|
excel = Excel.new(:reuse => false)
|
889
891
|
sheet = @book.sheet(1)
|
890
|
-
old_cell_value = sheet[1,1]
|
892
|
+
old_cell_value = sheet[1,1]
|
891
893
|
@book.close
|
892
894
|
@book.should_not be_alive
|
893
895
|
Workbook.unobtrusively(@simple_file1, :keep_open => true) do |book|
|
@@ -895,7 +897,7 @@ describe Workbook do
|
|
895
897
|
book.excel.should == @book.excel
|
896
898
|
book.excel.should_not == excel
|
897
899
|
sheet = book.sheet(1)
|
898
|
-
cell = sheet[1,1]
|
900
|
+
cell = sheet.range([1,1])
|
899
901
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
900
902
|
book.Saved.should be false
|
901
903
|
end
|
@@ -903,13 +905,13 @@ describe Workbook do
|
|
903
905
|
@book.close
|
904
906
|
new_book = Workbook.open(@simple_file1)
|
905
907
|
sheet = new_book.sheet(1)
|
906
|
-
sheet[1,1].
|
908
|
+
sheet[1,1].should_not == old_cell_value
|
907
909
|
end
|
908
910
|
|
909
911
|
it "should use the excel of the book and keep open the book" do
|
910
912
|
excel = Excel.new(:reuse => false)
|
911
913
|
sheet = @book.sheet(1)
|
912
|
-
old_cell_value = sheet[1,1]
|
914
|
+
old_cell_value = sheet[1,1]
|
913
915
|
@book.close
|
914
916
|
@book.should_not be_alive
|
915
917
|
Workbook.unobtrusively(@simple_file1, :if_closed => :current) do |book|
|
@@ -918,14 +920,14 @@ describe Workbook do
|
|
918
920
|
book.excel.should == @book.excel
|
919
921
|
book.excel.should_not == excel
|
920
922
|
sheet = book.sheet(1)
|
921
|
-
cell = sheet[1,1]
|
923
|
+
cell = sheet.range([1,1])
|
922
924
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
923
925
|
book.Saved.should be false
|
924
926
|
end
|
925
927
|
@book.should_not be_alive
|
926
928
|
new_book = Workbook.open(@simple_file1)
|
927
929
|
sheet = new_book.sheet(1)
|
928
|
-
sheet[1,1].
|
930
|
+
sheet[1,1].should_not == old_cell_value
|
929
931
|
end
|
930
932
|
end
|
931
933
|
|
@@ -992,7 +994,7 @@ describe Workbook do
|
|
992
994
|
@book1.Readonly.should == false
|
993
995
|
@book2.Readonly.should == true
|
994
996
|
old_sheet = @book1.sheet(1)
|
995
|
-
@old_cell_value = old_sheet[1,1]
|
997
|
+
@old_cell_value = old_sheet[1,1]
|
996
998
|
@book1.close
|
997
999
|
@book2.close
|
998
1000
|
@book1.should_not be_alive
|
@@ -1005,13 +1007,13 @@ describe Workbook do
|
|
1005
1007
|
book.excel.should_not == @book1.excel
|
1006
1008
|
book.ReadOnly.should == false
|
1007
1009
|
sheet = book.sheet(1)
|
1008
|
-
cell = sheet[1,1]
|
1010
|
+
cell = sheet.range([1,1])
|
1009
1011
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1010
1012
|
book.Saved.should be false
|
1011
1013
|
end
|
1012
1014
|
new_book = Workbook.open(@simple_file1)
|
1013
1015
|
sheet = new_book.sheet(1)
|
1014
|
-
sheet[1,1].
|
1016
|
+
sheet[1,1].should_not == @old_cell_value
|
1015
1017
|
end
|
1016
1018
|
|
1017
1019
|
end
|
@@ -1024,7 +1026,7 @@ describe Workbook do
|
|
1024
1026
|
before do
|
1025
1027
|
@book = Workbook.open(@simple_file1)
|
1026
1028
|
sheet = @book.sheet(1)
|
1027
|
-
@old_cell_value = sheet[1,1]
|
1029
|
+
@old_cell_value = sheet[1,1]
|
1028
1030
|
@book.close
|
1029
1031
|
end
|
1030
1032
|
|
@@ -1034,14 +1036,14 @@ describe Workbook do
|
|
1034
1036
|
book.should be_alive
|
1035
1037
|
book.Saved.should be true
|
1036
1038
|
sheet = book.sheet(1)
|
1037
|
-
cell = sheet[1,1]
|
1039
|
+
cell = sheet.range([1,1])
|
1038
1040
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1039
1041
|
book.Saved.should be false
|
1040
1042
|
book.excel.should == @book.excel
|
1041
1043
|
end
|
1042
1044
|
new_book = Workbook.open(@simple_file1, :visible => true)
|
1043
1045
|
sheet = new_book.sheet(1)
|
1044
|
-
sheet[1,1].
|
1046
|
+
sheet[1,1].should == @old_cell_value
|
1045
1047
|
end
|
1046
1048
|
|
1047
1049
|
|
@@ -1049,7 +1051,7 @@ describe Workbook do
|
|
1049
1051
|
new_excel = Excel.new(:reuse => false)
|
1050
1052
|
Workbook.for_reading(@simple_file1, :if_closed => :new) do |book|
|
1051
1053
|
sheet = book.sheet(1)
|
1052
|
-
cell = sheet[1,1]
|
1054
|
+
cell = sheet.range([1,1])
|
1053
1055
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1054
1056
|
book.excel.should_not == @book.excel
|
1055
1057
|
book.excel.should_not == new_excel
|
@@ -1058,19 +1060,19 @@ describe Workbook do
|
|
1058
1060
|
end
|
1059
1061
|
new_book = Workbook.open(@simple_file1, :visible => true)
|
1060
1062
|
sheet = new_book.sheet(1)
|
1061
|
-
sheet[1,1].
|
1063
|
+
sheet[1,1].should == @old_cell_value
|
1062
1064
|
end
|
1063
1065
|
|
1064
1066
|
it "should change the value" do
|
1065
1067
|
Workbook.for_modifying(@simple_file1) do |book|
|
1066
1068
|
sheet = book.sheet(1)
|
1067
|
-
cell = sheet[1,1]
|
1069
|
+
cell = sheet.range([1,1])
|
1068
1070
|
sheet[1,1] = cell.Value == "foo" ? "bar" : "foo"
|
1069
1071
|
book.excel.should == @book.excel
|
1070
1072
|
end
|
1071
1073
|
new_book = Workbook.open(@simple_file1, :visible => true)
|
1072
1074
|
sheet = new_book.sheet(1)
|
1073
|
-
sheet[1,1].
|
1075
|
+
sheet[1,1].should_not == @old_cell_value
|
1074
1076
|
end
|
1075
1077
|
end
|
1076
1078
|
end
|
@@ -1391,7 +1393,46 @@ describe Workbook do
|
|
1391
1393
|
end
|
1392
1394
|
end
|
1393
1395
|
|
1396
|
+
describe "#names" do
|
1397
|
+
|
1398
|
+
before do
|
1399
|
+
@book1 = Workbook.open(@another_simple_file)
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
it "should yield defined names" do
|
1403
|
+
@book1.names.should == ["another", "Sheet1!another_formula", "empty", "Sheet1!firstcell",
|
1404
|
+
"firstrow", "formula", "four", "Sheet1!localname", "Sheet2!localname",
|
1405
|
+
"named_formula", "new", "one", "Sheet1!simple"]
|
1406
|
+
end
|
1407
|
+
|
1408
|
+
end
|
1409
|
+
|
1410
|
+
describe "each" do
|
1411
|
+
|
1412
|
+
before do
|
1413
|
+
@book = Workbook.open(@simple_file)
|
1414
|
+
end
|
1415
|
+
|
1416
|
+
it "should do each" do
|
1417
|
+
@book.each do |sheet|
|
1418
|
+
sheet.should be_kind_of Worksheet
|
1419
|
+
end
|
1420
|
+
end
|
1421
|
+
|
1422
|
+
it "should map" do
|
1423
|
+
@book.map{|s| s}.should == [@book.sheet(1), @book.sheet(2), @book.sheet(3)]
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
it "should concatenate" do
|
1427
|
+
names = ""
|
1428
|
+
@book.each.with_index{|s,i| names << "#{s.name} #{i} " }
|
1429
|
+
names.should == "Sheet1 0 Sheet2 1 Sheet3 2 "
|
1430
|
+
end
|
1431
|
+
|
1432
|
+
end
|
1433
|
+
|
1394
1434
|
describe 'access sheet' do
|
1435
|
+
|
1395
1436
|
before do
|
1396
1437
|
@book = Workbook.open(@simple_file)
|
1397
1438
|
end
|
@@ -1435,7 +1476,7 @@ describe Workbook do
|
|
1435
1476
|
|
1436
1477
|
it "should keep the save state 'unsaved'" do
|
1437
1478
|
sheet = @book.sheet(1)
|
1438
|
-
sheet[1,1] = sheet[1,1]
|
1479
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
1439
1480
|
@book.Saved.should be false
|
1440
1481
|
@book.retain_saved do
|
1441
1482
|
sheet = @book.sheet(1)
|
@@ -1447,7 +1488,7 @@ describe Workbook do
|
|
1447
1488
|
|
1448
1489
|
it "should keep the save state 'unsaved' even when the workbook was saved before" do
|
1449
1490
|
sheet = @book.sheet(1)
|
1450
|
-
sheet[1,1] = sheet[1,1]
|
1491
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
1451
1492
|
@book.Saved.should be false
|
1452
1493
|
@book.retain_saved do
|
1453
1494
|
@book.save
|
@@ -9,5 +9,6 @@ require_relative 'workbook_close_spec'
|
|
9
9
|
require_relative 'workbook_save_spec'
|
10
10
|
require_relative 'workbook_misc_spec'
|
11
11
|
require_relative 'workbook_sheet_spec'
|
12
|
-
require_relative '
|
12
|
+
require_relative 'workbook
|
13
|
+
_unobtr_spec'
|
13
14
|
require_relative 'workbook_subclass_spec'
|
@@ -166,7 +166,7 @@ describe Workbook do
|
|
166
166
|
|
167
167
|
it "should keep the save state 'unsaved'" do
|
168
168
|
sheet = @book.sheet(1)
|
169
|
-
sheet[1,1] = sheet[1,1]
|
169
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
170
170
|
@book.Saved.should be false
|
171
171
|
@book.retain_saved do
|
172
172
|
sheet = @book.sheet(1)
|
@@ -180,7 +180,7 @@ describe Workbook do
|
|
180
180
|
@book.Saved.should be true
|
181
181
|
@book.retain_saved do
|
182
182
|
sheet = @book.sheet(1)
|
183
|
-
sheet[1,1] = sheet[1,1]
|
183
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
184
184
|
@book.Saved.should be false
|
185
185
|
end
|
186
186
|
@book.Saved.should be true
|
@@ -188,7 +188,7 @@ describe Workbook do
|
|
188
188
|
|
189
189
|
it "should keep the save state 'unsaved' even when the workbook was saved before" do
|
190
190
|
sheet = @book.sheet(1)
|
191
|
-
sheet[1,1] = sheet[1,1]
|
191
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
192
192
|
@book.Saved.should be false
|
193
193
|
@book.retain_saved do
|
194
194
|
@book.save
|
@@ -702,6 +702,13 @@ describe Workbook do
|
|
702
702
|
@book1.namevalue_global("new").should == "bar"
|
703
703
|
end
|
704
704
|
|
705
|
+
it "should set a range to a value with umlauts" do
|
706
|
+
@book1.sheet(1).add_name("lösung", [1,1])
|
707
|
+
@book1.namevalue_global("lösung").should == "foo"
|
708
|
+
@book1.set_namevalue_global("lösung","bar")
|
709
|
+
@book1.namevalue_global("lösung").should == "bar"
|
710
|
+
end
|
711
|
+
|
705
712
|
it "should set value of a range via []=" do
|
706
713
|
@book1["new"] = "bar"
|
707
714
|
@book1.namevalue_global("new").should == "bar"
|
@@ -717,7 +724,7 @@ describe Workbook do
|
|
717
724
|
|
718
725
|
it "should raise an error if name not defined and default value is not provided" do
|
719
726
|
expect {
|
720
|
-
@book1.namevalue_global("foo", :default =>
|
727
|
+
@book1.namevalue_global("foo", :default => 1)
|
721
728
|
}.to_not raise_error
|
722
729
|
expect {
|
723
730
|
@book1.namevalue_global("foo", :default => :__not_provided)
|
@@ -784,7 +791,7 @@ describe Workbook do
|
|
784
791
|
|
785
792
|
end
|
786
793
|
|
787
|
-
describe "
|
794
|
+
describe "rename_name" do
|
788
795
|
|
789
796
|
before do
|
790
797
|
@book1 = Workbook.open(@another_simple_file)
|
@@ -795,11 +802,11 @@ describe Workbook do
|
|
795
802
|
end
|
796
803
|
|
797
804
|
it "should rename a range" do
|
798
|
-
@book1.
|
805
|
+
@book1.rename_name("four","five")
|
799
806
|
@book1.namevalue_global("five").should == [[1,2],[3,4]]
|
800
807
|
expect {
|
801
|
-
@book1.
|
802
|
-
}.to raise_error(NameNotFound, /name "four" not in
|
808
|
+
@book1.rename_name("four","five")
|
809
|
+
}.to raise_error(NameNotFound, /name "four" not in/)
|
803
810
|
end
|
804
811
|
end
|
805
812
|
|
@@ -901,7 +908,7 @@ describe Workbook do
|
|
901
908
|
|
902
909
|
it "should yield false for an unsaved book" do
|
903
910
|
sheet = @book.sheet(1)
|
904
|
-
sheet[1,1] = sheet[1,1]
|
911
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
905
912
|
@book.saved.should be false
|
906
913
|
end
|
907
914
|
end
|
@@ -1065,20 +1072,20 @@ describe Workbook do
|
|
1065
1072
|
it "should bring a book to focus" do
|
1066
1073
|
sheet = @book.sheet(2)
|
1067
1074
|
sheet.Activate
|
1068
|
-
sheet[2,3].Activate
|
1075
|
+
sheet.range([2,3]).Activate
|
1069
1076
|
sheet2 = @book2.sheet(2)
|
1070
1077
|
sheet2.Activate
|
1071
|
-
sheet2[3,2].Activate
|
1078
|
+
sheet2.range([3,2]).Activate
|
1072
1079
|
Excel.current.should == @book.excel
|
1073
1080
|
@book2.focus
|
1074
1081
|
@key_sender.puts "{a}{enter}"
|
1075
1082
|
sleep 1
|
1076
|
-
#sheet2[3,2].Value.should == "a"
|
1083
|
+
#sheet2.range([3,2]).Value.should == "a"
|
1077
1084
|
#Excel.current.should == @book2.excel
|
1078
1085
|
@book.focus
|
1079
1086
|
@key_sender.puts "{a}{enter}"
|
1080
1087
|
sleep 1
|
1081
|
-
#sheet[2,3].Value.should == "a"
|
1088
|
+
#sheet.range([2,3]).Value.should == "a"
|
1082
1089
|
Excel.current.should == @book.excel
|
1083
1090
|
end
|
1084
1091
|
end
|
@@ -138,7 +138,7 @@ describe Workbook do
|
|
138
138
|
book.should be_alive
|
139
139
|
book.should be_a Workbook
|
140
140
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
141
|
-
Excel.
|
141
|
+
Excel.instance_count.should == 1
|
142
142
|
end
|
143
143
|
end
|
144
144
|
end
|
@@ -234,7 +234,7 @@ describe Workbook do
|
|
234
234
|
book.should be_alive
|
235
235
|
book.should be_a Workbook
|
236
236
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
237
|
-
Excel.
|
237
|
+
Excel.instance_count.should == 1
|
238
238
|
end
|
239
239
|
end
|
240
240
|
end
|
@@ -451,7 +451,7 @@ describe Workbook do
|
|
451
451
|
book.filename.should == @simple_file_network_path1
|
452
452
|
book.Fullname.should == @ole_wb.Fullname
|
453
453
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
454
|
-
Excel.
|
454
|
+
Excel.instance_count.should == 1
|
455
455
|
book.excel.Workbooks.Count.should == 1
|
456
456
|
end
|
457
457
|
end
|
@@ -467,7 +467,7 @@ describe Workbook do
|
|
467
467
|
book.filename.should == @simple_file_hostname_share_path1.downcase
|
468
468
|
book.Fullname.should == @ole_wb.Fullname
|
469
469
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
470
|
-
Excel.
|
470
|
+
Excel.instance_count.should == 1
|
471
471
|
book.excel.Workbooks.Count.should == 1
|
472
472
|
end
|
473
473
|
end
|
@@ -523,7 +523,7 @@ describe Workbook do
|
|
523
523
|
book.filename.should == @simple_file_network_path1
|
524
524
|
book.Fullname.should == @ole_wb.Fullname
|
525
525
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
526
|
-
Excel.
|
526
|
+
Excel.instance_count.should == 1
|
527
527
|
book.excel.Workbooks.Count.should == 1
|
528
528
|
end
|
529
529
|
end
|
@@ -539,7 +539,7 @@ describe Workbook do
|
|
539
539
|
book.filename.should == @simple_file_hostname_share_path1.downcase
|
540
540
|
book.Fullname.should == @ole_wb.Fullname
|
541
541
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
542
|
-
Excel.
|
542
|
+
Excel.instance_count.should == 1
|
543
543
|
book.excel.Workbooks.Count.should == 1
|
544
544
|
end
|
545
545
|
end
|
@@ -637,11 +637,11 @@ describe Workbook do
|
|
637
637
|
|
638
638
|
it "should connect to an unknown hostname share path workbook" do
|
639
639
|
Workbook.open(@simple_file_hostname_share_path1) do |book|
|
640
|
-
book.filename.should == @
|
640
|
+
book.filename.should == @simple_file_network_path1
|
641
641
|
book.should be_alive
|
642
642
|
book.should be_a Workbook
|
643
643
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
644
|
-
Excel.
|
644
|
+
Excel.instance_count.should == 1
|
645
645
|
book.excel.Workbooks.Count.should == 1
|
646
646
|
end
|
647
647
|
end
|
@@ -660,7 +660,7 @@ describe Workbook do
|
|
660
660
|
book1 = Workbook.open(@simple_file1)
|
661
661
|
book1.should be_alive
|
662
662
|
book1.should be_a Workbook
|
663
|
-
Excel.
|
663
|
+
Excel.instance_count.should == 1
|
664
664
|
book1.ReadOnly.should be false
|
665
665
|
book1.excel.Visible.should be false
|
666
666
|
book1.CheckCompatibility.should be true
|
@@ -679,7 +679,7 @@ describe Workbook do
|
|
679
679
|
book1.should be_alive
|
680
680
|
book1.should be_a Workbook
|
681
681
|
book1.excel.should == excel1
|
682
|
-
Excel.
|
682
|
+
Excel.instance_count.should == 1
|
683
683
|
book1.excel.Visible.should be false
|
684
684
|
end
|
685
685
|
|
@@ -689,7 +689,7 @@ describe Workbook do
|
|
689
689
|
book1.should be_alive
|
690
690
|
book1.should be_a Workbook
|
691
691
|
book1.excel.should == excel1
|
692
|
-
Excel.
|
692
|
+
Excel.instance_count.should == 1
|
693
693
|
book1.excel.Visible.should be true
|
694
694
|
end
|
695
695
|
|
@@ -699,7 +699,7 @@ describe Workbook do
|
|
699
699
|
book1.should be_alive
|
700
700
|
book1.should be_a Workbook
|
701
701
|
book1.excel.should_not == excel1
|
702
|
-
Excel.
|
702
|
+
Excel.instance_count.should == 2
|
703
703
|
end
|
704
704
|
|
705
705
|
it "should set the options in a given known Excel" do
|
@@ -714,7 +714,7 @@ describe Workbook do
|
|
714
714
|
book1 = Workbook.open(@simple_file1)
|
715
715
|
book1.should be_alive
|
716
716
|
book1.should be_a Workbook
|
717
|
-
Excel.
|
717
|
+
Excel.instance_count.should == 1
|
718
718
|
book1.excel.ole_excel.Hwnd.should == ole_excel1.Hwnd
|
719
719
|
end
|
720
720
|
|
@@ -735,7 +735,7 @@ describe Workbook do
|
|
735
735
|
book.should be_alive
|
736
736
|
book.should be_a Workbook
|
737
737
|
book.excel.ole_excel.Hwnd.should == @ole_wb.Application.Hwnd
|
738
|
-
Excel.
|
738
|
+
Excel.instance_count.should == 1
|
739
739
|
end
|
740
740
|
end
|
741
741
|
|
@@ -815,7 +815,7 @@ describe Workbook do
|
|
815
815
|
Workbook.open(@simple_file1) do |book|
|
816
816
|
book.filename.should == @simple_file1
|
817
817
|
book.excel.ole_excel.Hwnd.should == @ole_wb1.Application.Hwnd
|
818
|
-
Excel.
|
818
|
+
Excel.instance_count.should == 2
|
819
819
|
end
|
820
820
|
end
|
821
821
|
|
@@ -823,7 +823,7 @@ describe Workbook do
|
|
823
823
|
Workbook.open(@different_file1) do |book|
|
824
824
|
book.filename.should == @different_file1
|
825
825
|
book.excel.ole_excel.Hwnd.should == @ole_wb2.Application.Hwnd
|
826
|
-
Excel.
|
826
|
+
Excel.instance_count.should == 2
|
827
827
|
end
|
828
828
|
end
|
829
829
|
|
@@ -912,9 +912,9 @@ describe Workbook do
|
|
912
912
|
before do
|
913
913
|
@book = Workbook.open(@simple_file1, :if_unsaved => :accept)
|
914
914
|
sheet = @book.sheet(1)
|
915
|
-
@old_value = sheet[1,1]
|
916
|
-
sheet[1,1] = (sheet[1,1]
|
917
|
-
@new_value = sheet[1,1]
|
915
|
+
@old_value = sheet[1,1]
|
916
|
+
sheet[1,1] = (sheet[1,1] == "foo" ? "bar" : "foo")
|
917
|
+
@new_value = sheet[1,1]
|
918
918
|
@book.Saved.should be false
|
919
919
|
end
|
920
920
|
|
@@ -928,7 +928,7 @@ describe Workbook do
|
|
928
928
|
new_book.should be_alive
|
929
929
|
new_book.Saved.should be false
|
930
930
|
@book.Saved.should be false
|
931
|
-
new_book.sheet(1)[1,1].
|
931
|
+
new_book.sheet(1)[1,1].should == @new_value
|
932
932
|
new_book.should == @book
|
933
933
|
end
|
934
934
|
|
@@ -2599,7 +2599,7 @@ describe Workbook do
|
|
2599
2599
|
|
2600
2600
|
it "should new_excel" do
|
2601
2601
|
book = Workbook.open(@simple_file1)
|
2602
|
-
book.sheet(1)[1,1]
|
2602
|
+
book.sheet(1)[1,1] = "foo"
|
2603
2603
|
book.Saved.should be false
|
2604
2604
|
book2 = Workbook.open(@simple_file1, :if_unsaved => :new_excel)
|
2605
2605
|
end
|
@@ -2667,10 +2667,11 @@ describe Workbook do
|
|
2667
2667
|
@key_sender.puts "{right}{enter}"
|
2668
2668
|
@key_sender.puts "{right}{enter}"
|
2669
2669
|
@key_sender.puts "{right}{enter}"
|
2670
|
-
expect{
|
2670
|
+
#expect{
|
2671
2671
|
Workbook.open(@simple_file, :if_unsaved => :alert)
|
2672
|
-
|
2672
|
+
# }.to raise_error(UnexpectedREOError)
|
2673
2673
|
@book.should be_alive
|
2674
|
+
@book.Saved.should be false
|
2674
2675
|
end
|
2675
2676
|
|
2676
2677
|
it "should not open the new book and not close the unsaved book, if user answers 'no'" do
|
@@ -2679,10 +2680,11 @@ describe Workbook do
|
|
2679
2680
|
@key_sender.puts "{right}{enter}"
|
2680
2681
|
@key_sender.puts "{right}{enter}"
|
2681
2682
|
@key_sender.puts "{right}{enter}"
|
2682
|
-
expect{
|
2683
|
+
#expect{
|
2683
2684
|
Workbook.open(@simple_file, :if_unsaved => :excel)
|
2684
|
-
}.to raise_error(UnexpectedREOError)
|
2685
|
+
#}.to raise_error(UnexpectedREOError)
|
2685
2686
|
@book.should be_alive
|
2687
|
+
@book.Saved.should be false
|
2686
2688
|
end
|
2687
2689
|
|
2688
2690
|
end
|
@@ -2704,9 +2706,9 @@ describe Workbook do
|
|
2704
2706
|
#@sheet_count = @book.ole_workbook.Worksheets.Count
|
2705
2707
|
sheet = @book.sheet(1)
|
2706
2708
|
#@book.add_sheet(@sheet, :as => 'a_name')
|
2707
|
-
@old_value = sheet[1,1]
|
2708
|
-
sheet[1,1] = (sheet[1,1]
|
2709
|
-
@new_value = sheet[1,1]
|
2709
|
+
@old_value = sheet[1,1]
|
2710
|
+
sheet[1,1] = (sheet[1,1] == "foo" ? "bar" : "foo")
|
2711
|
+
@new_value = sheet[1,1]
|
2710
2712
|
@book.Saved.should be false
|
2711
2713
|
end
|
2712
2714
|
|
@@ -2727,7 +2729,7 @@ describe Workbook do
|
|
2727
2729
|
new_book.should be_alive
|
2728
2730
|
new_book.filename.downcase.should == @simple_file.downcase
|
2729
2731
|
old_book = Workbook.open(@simple_file_other_path1, :if_obstructed => :forget)
|
2730
|
-
old_book.sheet(1)[1,1].
|
2732
|
+
old_book.sheet(1)[1,1].should == @old_value
|
2731
2733
|
end
|
2732
2734
|
|
2733
2735
|
it "should save the old book, close it, and open the new book, if :if_obstructed is :save" do
|
@@ -2736,7 +2738,7 @@ describe Workbook do
|
|
2736
2738
|
new_book.should be_alive
|
2737
2739
|
new_book.filename.downcase.should == @simple_file1.downcase
|
2738
2740
|
old_book = Workbook.open(@simple_file_other_path1, :if_obstructed => :forget)
|
2739
|
-
old_book.sheet(1)[1,1].
|
2741
|
+
old_book.sheet(1)[1,1].should == @new_value
|
2740
2742
|
#old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
2741
2743
|
old_book.close
|
2742
2744
|
end
|
@@ -2752,7 +2754,7 @@ describe Workbook do
|
|
2752
2754
|
new_book.should be_alive
|
2753
2755
|
new_book.filename.downcase.should == @simple_file1.downcase
|
2754
2756
|
old_book = Workbook.open(@simple_file_other_path1, :if_obstructed => :forget)
|
2755
|
-
old_book.sheet(1)[1,1].
|
2757
|
+
old_book.sheet(1)[1,1].should == @new_value
|
2756
2758
|
#old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
|
2757
2759
|
old_book.close
|
2758
2760
|
end
|
@@ -2767,11 +2769,11 @@ describe Workbook do
|
|
2767
2769
|
new_book = Workbook.open(@simple_file1, :if_obstructed => :new_excel)
|
2768
2770
|
@book.should be_alive
|
2769
2771
|
@book.Saved.should be false
|
2770
|
-
@book.sheet(1)[1,1].
|
2772
|
+
@book.sheet(1)[1,1].should == @new_value
|
2771
2773
|
new_book.should be_alive
|
2772
2774
|
new_book.filename.should_not == @book.filename
|
2773
2775
|
new_book.excel.should_not == @book.excel
|
2774
|
-
new_book.sheet(1)[1,1].
|
2776
|
+
new_book.sheet(1)[1,1].should == @book.sheet(1)[1,1]
|
2775
2777
|
end
|
2776
2778
|
|
2777
2779
|
it "should raise an error, if :if_obstructed is default" do
|
@@ -2917,8 +2919,8 @@ describe Workbook do
|
|
2917
2919
|
book.ReadOnly.should be true
|
2918
2920
|
book.should be_alive
|
2919
2921
|
sheet = book.sheet(1)
|
2920
|
-
old_cell_value = sheet[1,1]
|
2921
|
-
sheet[1,1] = sheet[1,1]
|
2922
|
+
old_cell_value = sheet[1,1]
|
2923
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
2922
2924
|
book.Saved.should be false
|
2923
2925
|
expect{
|
2924
2926
|
new_book = Workbook.open(@simple_file1, :read_only => false, :if_unsaved => :accept)
|
@@ -2930,8 +2932,8 @@ describe Workbook do
|
|
2930
2932
|
book.ReadOnly.should be false
|
2931
2933
|
book.should be_alive
|
2932
2934
|
sheet = book.sheet(1)
|
2933
|
-
old_cell_value = sheet[1,1]
|
2934
|
-
sheet[1,1] = sheet[1,1]
|
2935
|
+
old_cell_value = sheet[1,1]
|
2936
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
2935
2937
|
book.Saved.should be false
|
2936
2938
|
expect{
|
2937
2939
|
new_book = Workbook.open(@simple_file1, :read_only => true, :if_unsaved => :accept)
|
@@ -2943,8 +2945,8 @@ describe Workbook do
|
|
2943
2945
|
book.ReadOnly.should be true
|
2944
2946
|
book.should be_alive
|
2945
2947
|
sheet = book.sheet(1)
|
2946
|
-
old_cell_value = sheet[1,1]
|
2947
|
-
sheet[1,1] = sheet[1,1]
|
2948
|
+
old_cell_value = sheet[1,1]
|
2949
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
2948
2950
|
book.Saved.should be false
|
2949
2951
|
new_book = Workbook.open(@simple_file1, :read_only => false, :if_unsaved => :forget)
|
2950
2952
|
new_book.ReadOnly.should be false
|
@@ -2952,7 +2954,7 @@ describe Workbook do
|
|
2952
2954
|
book.should_not be_alive
|
2953
2955
|
new_book.should_not == book
|
2954
2956
|
new_sheet = new_book.sheet(1)
|
2955
|
-
new_cell_value = new_sheet[1,1]
|
2957
|
+
new_cell_value = new_sheet[1,1]
|
2956
2958
|
new_cell_value.should == old_cell_value
|
2957
2959
|
end
|
2958
2960
|
|
@@ -2961,8 +2963,8 @@ describe Workbook do
|
|
2961
2963
|
book.ReadOnly.should be false
|
2962
2964
|
book.should be_alive
|
2963
2965
|
sheet = book.sheet(1)
|
2964
|
-
old_cell_value = sheet[1,1]
|
2965
|
-
sheet[1,1] = sheet[1,1]
|
2966
|
+
old_cell_value = sheet[1,1]
|
2967
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
2966
2968
|
book.Saved.should be false
|
2967
2969
|
expect{
|
2968
2970
|
Workbook.open(@simple_file1, :read_only => true, :if_unsaved => :accept)
|
@@ -2974,13 +2976,13 @@ describe Workbook do
|
|
2974
2976
|
book.ReadOnly.should be false
|
2975
2977
|
book.should be_alive
|
2976
2978
|
sheet = book.sheet(1)
|
2977
|
-
old_cell_value = sheet[1,1]
|
2978
|
-
sheet[1,1] = sheet[1,1]
|
2979
|
+
old_cell_value = sheet[1,1]
|
2980
|
+
sheet[1,1] = sheet[1,1] == "foo" ? "bar" : "foo"
|
2979
2981
|
book.Saved.should be false
|
2980
2982
|
new_book = Workbook.open(@simple_file1, :read_only => true, :if_unsaved => :save)
|
2981
2983
|
new_book.ReadOnly.should be true
|
2982
2984
|
new_sheet = new_book.sheet(1)
|
2983
|
-
new_cell_value = new_sheet[1,1]
|
2985
|
+
new_cell_value = new_sheet[1,1]
|
2984
2986
|
new_cell_value.should_not == old_cell_value
|
2985
2987
|
end
|
2986
2988
|
|