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/spec/spec_helper.rb
CHANGED
@@ -2,10 +2,24 @@
|
|
2
2
|
require "rspec"
|
3
3
|
require 'tmpdir'
|
4
4
|
require "fileutils"
|
5
|
-
|
5
|
+
require_relative '../lib/robust_excel_ole'
|
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
|
6
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
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'spec_helper'
|
4
4
|
require 'pathname'
|
5
5
|
|
6
6
|
$VERBOSE = nil
|
@@ -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
|
@@ -1103,12 +1105,12 @@ describe Workbook do
|
|
1103
1105
|
end
|
1104
1106
|
|
1105
1107
|
it "should return value of a range" do
|
1106
|
-
@book1.
|
1107
|
-
@book1.
|
1108
|
-
@book1.
|
1109
|
-
@book1.
|
1110
|
-
@book1.
|
1111
|
-
@book1.
|
1108
|
+
@book1.namevalue_global("new").should == "foo"
|
1109
|
+
@book1.namevalue_global("one").should == 1
|
1110
|
+
@book1.namevalue_global("firstrow").should == [[1,2]]
|
1111
|
+
@book1.namevalue_global("four").should == [[1,2],[3,4]]
|
1112
|
+
@book1.namevalue_global("firstrow").should_not == "12"
|
1113
|
+
@book1.namevalue_global("firstcell").should == "foo"
|
1112
1114
|
end
|
1113
1115
|
|
1114
1116
|
it "should return value of a range via []" do
|
@@ -1121,17 +1123,17 @@ describe Workbook do
|
|
1121
1123
|
end
|
1122
1124
|
|
1123
1125
|
it "should set value of a range" do
|
1124
|
-
@book1.
|
1125
|
-
@book1.
|
1126
|
+
@book1.set_namevalue_global("new", "bar")
|
1127
|
+
@book1.namevalue_global("new").should == "bar"
|
1126
1128
|
end
|
1127
1129
|
|
1128
1130
|
it "should set value of a range via []=" do
|
1129
1131
|
@book1["new"] = "bar"
|
1130
|
-
@book1.
|
1132
|
+
@book1.namevalue_global("new").should == "bar"
|
1131
1133
|
end
|
1132
1134
|
|
1133
1135
|
#it "should evaluate a formula" do
|
1134
|
-
# @book1.
|
1136
|
+
# @book1.namevalue_global("named_formula").should == 4
|
1135
1137
|
#end
|
1136
1138
|
|
1137
1139
|
#it "should evaluate a formula via []" do
|
@@ -1139,7 +1141,7 @@ describe Workbook do
|
|
1139
1141
|
#end
|
1140
1142
|
|
1141
1143
|
#it "should return default value if name not defined" do
|
1142
|
-
# @book1.
|
1144
|
+
# @book1.namevalue_global("foo", :default => 2).should == 2
|
1143
1145
|
#end
|
1144
1146
|
|
1145
1147
|
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
|
@@ -1,33 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../spec_helper'
|
4
4
|
|
5
5
|
$VERBOSE = nil
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=begin
|
16
|
-
$VERBOSE = nil
|
17
|
-
|
18
|
-
include General
|
19
|
-
|
20
|
-
unless Object.method_defined?(:require_relative)
|
21
|
-
def require_relative path
|
22
|
-
require File.expand_path(path, File.dirname(__FILE__))
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
require_relative "workbook_open_spec"
|
27
|
-
require_relative "workbook_close_spec"
|
28
|
-
require_relative "workbook_save_spec"
|
29
|
-
require_relative "workbook_misc_spec"
|
30
|
-
require_relative "workbook_sheet_spec"
|
31
|
-
require_relative "workbook_unobtr_spec"
|
32
|
-
require_relative "workbook_subclass_spec"
|
33
|
-
=end
|
7
|
+
require_relative 'workbook_open_spec'
|
8
|
+
require_relative 'workbook_close_spec'
|
9
|
+
require_relative 'workbook_save_spec'
|
10
|
+
require_relative 'workbook_misc_spec'
|
11
|
+
require_relative 'workbook_sheet_spec'
|
12
|
+
require_relative 'workbook
|
13
|
+
_unobtr_spec'
|
14
|
+
require_relative 'workbook_subclass_spec'
|
@@ -1,13 +1,14 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require_relative '../spec_helper'
|
5
4
|
|
6
5
|
$VERBOSE = nil
|
7
6
|
|
8
7
|
include RobustExcelOle
|
9
8
|
include General
|
10
9
|
|
10
|
+
using ToReoRefinement
|
11
|
+
|
11
12
|
describe Workbook do
|
12
13
|
|
13
14
|
before(:all) do
|
@@ -24,7 +25,6 @@ describe Workbook do
|
|
24
25
|
@different_file = @dir + '/different_workbook.xls'
|
25
26
|
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
26
27
|
@another_simple_file = @dir + '/another_workbook.xls'
|
27
|
-
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
28
|
@simple_file_xlsm = @dir + '/workbook.xls'
|
29
29
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
30
|
@simple_file1 = @simple_file
|
@@ -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
|
@@ -669,7 +669,7 @@ describe Workbook do
|
|
669
669
|
end
|
670
670
|
end
|
671
671
|
|
672
|
-
describe "
|
672
|
+
describe "namevalue_global, set_namevalue_global, [], []=" do
|
673
673
|
|
674
674
|
before do
|
675
675
|
@book1 = Workbook.open(@another_simple_file)
|
@@ -680,12 +680,12 @@ describe Workbook do
|
|
680
680
|
end
|
681
681
|
|
682
682
|
it "should return value of a range" do
|
683
|
-
@book1.
|
684
|
-
@book1.
|
685
|
-
@book1.
|
686
|
-
@book1.
|
687
|
-
@book1.
|
688
|
-
@book1.
|
683
|
+
@book1.namevalue_global("new").should == "foo"
|
684
|
+
@book1.namevalue_global("one").should == 1
|
685
|
+
@book1.namevalue_global("firstrow").should == [[1,2]]
|
686
|
+
@book1.namevalue_global("four").should == [[1,2],[3,4]]
|
687
|
+
@book1.namevalue_global("firstrow").should_not == "12"
|
688
|
+
@book1.namevalue_global("firstcell").should == "foo"
|
689
689
|
end
|
690
690
|
|
691
691
|
it "should return value of a range via []" do
|
@@ -698,17 +698,24 @@ describe Workbook do
|
|
698
698
|
end
|
699
699
|
|
700
700
|
it "should set value of a range" do
|
701
|
-
@book1.
|
702
|
-
@book1.
|
701
|
+
@book1.set_namevalue_global("new", "bar")
|
702
|
+
@book1.namevalue_global("new").should == "bar"
|
703
|
+
end
|
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"
|
703
710
|
end
|
704
711
|
|
705
712
|
it "should set value of a range via []=" do
|
706
713
|
@book1["new"] = "bar"
|
707
|
-
@book1.
|
714
|
+
@book1.namevalue_global("new").should == "bar"
|
708
715
|
end
|
709
716
|
|
710
717
|
#it "should evaluate a formula" do
|
711
|
-
# @book1.
|
718
|
+
# @book1.namevalue_global("named_formula").should == 4
|
712
719
|
#end
|
713
720
|
|
714
721
|
#it "should evaluate a formula via []" do
|
@@ -717,28 +724,28 @@ 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.
|
727
|
+
@book1.namevalue_global("foo", :default => 1)
|
721
728
|
}.to_not raise_error
|
722
729
|
expect {
|
723
|
-
@book1.
|
730
|
+
@book1.namevalue_global("foo", :default => :__not_provided)
|
724
731
|
}.to raise_error(NameNotFound, /name "foo" not in #<Workbook: another_workbook/)
|
725
732
|
expect {
|
726
|
-
@book1.
|
733
|
+
@book1.namevalue_global("foo")
|
727
734
|
}.to raise_error(NameNotFound, /name "foo" not in #<Workbook: another_workbook/)
|
728
|
-
@book1.
|
729
|
-
@book1.
|
735
|
+
@book1.namevalue_global("foo", :default => nil).should be_nil
|
736
|
+
@book1.namevalue_global("foo", :default => 1).should == 1
|
730
737
|
expect {
|
731
|
-
@book1.
|
738
|
+
@book1.set_namevalue_global("foo","bar")
|
732
739
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
733
740
|
expect {
|
734
741
|
@book1["foo"] = "bar"
|
735
742
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "foo"/)
|
736
|
-
@book1.
|
743
|
+
@book1.namevalue_global("empty", :default => 1).should be_nil
|
737
744
|
end
|
738
745
|
|
739
746
|
it "should raise an error if name was defined but contents is calcuated" do
|
740
747
|
expect {
|
741
|
-
@book1.
|
748
|
+
@book1.set_namevalue_global("named_formula","bar")
|
742
749
|
}.to raise_error(RangeNotEvaluatable, /cannot assign value to range named "named_formula" in #<Workbook: another_workbook/)
|
743
750
|
expect {
|
744
751
|
@book1["named_formula"] = "bar"
|
@@ -747,19 +754,19 @@ describe Workbook do
|
|
747
754
|
|
748
755
|
# Excel Bug: for local names without uqifier: takes the first sheet as default even if another sheet is activated
|
749
756
|
it "should take the first sheet as default even if the second sheet is activated" do
|
750
|
-
@book1.
|
751
|
-
@book1.
|
752
|
-
@book1.
|
757
|
+
@book1.namevalue_global("Sheet1!localname").should == "bar"
|
758
|
+
@book1.namevalue_global("Sheet2!localname").should == "simple"
|
759
|
+
@book1.namevalue_global("localname").should == "bar"
|
753
760
|
@book1.Worksheets.Item(2).Activate
|
754
|
-
@book1.
|
761
|
+
@book1.namevalue_global("localname").should == "bar"
|
755
762
|
@book1.Worksheets.Item(1).Delete
|
756
|
-
@book1.
|
763
|
+
@book1.namevalue_global("localname").should == "simple"
|
757
764
|
end
|
758
765
|
|
759
766
|
it "should color the cell (deprecated)" do
|
760
|
-
@book1.
|
767
|
+
@book1.set_namevalue_global("new", "bar")
|
761
768
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
762
|
-
@book1.
|
769
|
+
@book1.set_namevalue_global("new", "bar", :color => 4)
|
763
770
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
764
771
|
@book1["new"].should == "bar"
|
765
772
|
@book1["new"] = "bar"
|
@@ -771,9 +778,9 @@ describe Workbook do
|
|
771
778
|
end
|
772
779
|
|
773
780
|
it "should color the cell" do
|
774
|
-
@book1.
|
781
|
+
@book1.set_namevalue_global("new", "bar")
|
775
782
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
|
776
|
-
@book1.
|
783
|
+
@book1.set_namevalue_global("new", "bar", :color => 4)
|
777
784
|
@book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
|
778
785
|
@book1["new"].should == "bar"
|
779
786
|
@book1["new"] = "bar"
|
@@ -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.
|
799
|
-
@book1.
|
805
|
+
@book1.rename_name("four","five")
|
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
|
@@ -1165,7 +1172,7 @@ describe Workbook do
|
|
1165
1172
|
@book1.add_name("foo",[1,1])
|
1166
1173
|
@book1.delete_name("foo")
|
1167
1174
|
expect{
|
1168
|
-
@book1.
|
1175
|
+
@book1.namevalue_global("foo")
|
1169
1176
|
}.to raise_error(NameNotFound, /name "foo"/)
|
1170
1177
|
end
|
1171
1178
|
|