robust_excel_ole 0.4 → 0.5
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.
- data/.gitignore +1 -0
- data/Changelog +15 -0
- data/README.rdoc +128 -63
- data/README_detail.rdoc +130 -60
- data/examples/edit_sheets/example_access_sheets_and_cells.rb +1 -1
- data/examples/edit_sheets/example_adding_sheets.rb +2 -2
- data/examples/edit_sheets/example_copying.rb +1 -1
- data/examples/edit_sheets/example_expanding.rb +1 -1
- data/examples/edit_sheets/example_ranges.rb +1 -1
- data/examples/edit_sheets/example_saving.rb +2 -2
- data/examples/open_save_close/example_control_to_excel.rb +1 -1
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +3 -3
- data/examples/open_save_close/example_read_only.rb +1 -1
- data/examples/open_save_close/example_rename_cells.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 +1 -0
- data/lib/robust_excel_ole/book.rb +249 -193
- data/lib/robust_excel_ole/bookstore.rb +1 -1
- data/lib/robust_excel_ole/cell.rb +1 -1
- data/lib/robust_excel_ole/excel.rb +125 -4
- data/lib/robust_excel_ole/general.rb +1 -92
- data/lib/robust_excel_ole/range.rb +1 -1
- data/lib/robust_excel_ole/reo_common.rb +37 -0
- data/lib/robust_excel_ole/sheet.rb +77 -24
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_spec.rb +112 -82
- data/spec/book_specs/book_close_spec.rb +44 -1
- data/spec/book_specs/book_misc_spec.rb +97 -92
- data/spec/book_specs/book_open_spec.rb +40 -8
- data/spec/book_specs/book_save_spec.rb +77 -7
- data/spec/book_specs/book_sheet_spec.rb +290 -66
- data/spec/book_specs/book_unobtr_spec.rb +99 -73
- data/spec/bookstore_spec.rb +1 -1
- data/spec/cell_spec.rb +2 -2
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +174 -23
- data/spec/general_spec.rb +3 -18
- data/spec/range_spec.rb +3 -3
- data/spec/reo_common_spec.rb +104 -0
- data/spec/sheet_spec.rb +101 -60
- metadata +6 -4
data/spec/bookstore_spec.rb
CHANGED
@@ -279,7 +279,7 @@ describe Bookstore do
|
|
279
279
|
@book3 = Book.open(@simple_file, :force_excel => :new)
|
280
280
|
@bookstore.store(@book2)
|
281
281
|
@bookstore.store(@book3)
|
282
|
-
sheet = @book3
|
282
|
+
sheet = @book3.sheet(1)
|
283
283
|
sheet[1,1] = sheet[1,1].Value == "foo" ? "bar" : "foo"
|
284
284
|
@book.ReadOnly.should be_true
|
285
285
|
@book2.ReadOnly.should be_false
|
data/spec/cell_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Cell do
|
|
23
23
|
context "open simple.xls" do
|
24
24
|
before do
|
25
25
|
@book = Book.open(@dir + '/workbook.xls', :read_only => true)
|
26
|
-
@sheet = @book
|
26
|
+
@sheet = @book.sheet(2)
|
27
27
|
@cell = @sheet[1, 1]
|
28
28
|
end
|
29
29
|
|
@@ -55,7 +55,7 @@ describe Cell do
|
|
55
55
|
context "open merge_cells.xls" do
|
56
56
|
before do
|
57
57
|
@book = Book.open(@dir + '/merge_cells.xls', :read_only => true)
|
58
|
-
@sheet = @book
|
58
|
+
@sheet = @book.sheet(1)
|
59
59
|
end
|
60
60
|
|
61
61
|
after do
|
Binary file
|
data/spec/data/workbook.xls
CHANGED
Binary file
|
data/spec/excel_spec.rb
CHANGED
@@ -11,7 +11,7 @@ module RobustExcelOle
|
|
11
11
|
describe Excel do
|
12
12
|
|
13
13
|
before(:all) do
|
14
|
-
Excel.
|
14
|
+
Excel.kill_all
|
15
15
|
end
|
16
16
|
|
17
17
|
before do
|
@@ -321,10 +321,10 @@ module RobustExcelOle
|
|
321
321
|
@excel1 = book1.excel
|
322
322
|
@excel2 = book2.excel
|
323
323
|
@excel4 = book4.excel
|
324
|
-
sheet2 = book2
|
324
|
+
sheet2 = book2.sheet(1)
|
325
325
|
@old_cell_value2 = sheet2[1,1].value
|
326
326
|
sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
|
327
|
-
sheet3 = book3
|
327
|
+
sheet3 = book3.sheet(1)
|
328
328
|
@old_cell_value3 = sheet3[1,1].value
|
329
329
|
sheet3[1,1] = sheet3[1,1].value == "foo" ? "bar" : "foo"
|
330
330
|
end
|
@@ -342,11 +342,11 @@ module RobustExcelOle
|
|
342
342
|
@excel2.should_not be_alive
|
343
343
|
@excel4.should_not be_alive
|
344
344
|
new_book2 = Book.open(@simple_file)
|
345
|
-
new_sheet2 = new_book2
|
345
|
+
new_sheet2 = new_book2.sheet(1)
|
346
346
|
new_sheet2[1,1].value.should == @old_cell_value2
|
347
347
|
new_book2.close
|
348
348
|
new_book3 = Book.open(@another_simple_file)
|
349
|
-
new_sheet3 = new_book3
|
349
|
+
new_sheet3 = new_book3.sheet(1)
|
350
350
|
new_sheet3[1,1].value.should == @old_cell_value3
|
351
351
|
new_book3.close
|
352
352
|
end
|
@@ -357,11 +357,11 @@ module RobustExcelOle
|
|
357
357
|
@excel2.should_not be_alive
|
358
358
|
@excel4.should_not be_alive
|
359
359
|
new_book2 = Book.open(@simple_file)
|
360
|
-
new_sheet2 = new_book2
|
360
|
+
new_sheet2 = new_book2.sheet(1)
|
361
361
|
new_sheet2[1,1].value.should_not == @old_cell_value2
|
362
362
|
new_book2.close
|
363
363
|
new_book3 = Book.open(@another_simple_file)
|
364
|
-
new_sheet3 = new_book3
|
364
|
+
new_sheet3 = new_book3.sheet(1)
|
365
365
|
new_sheet3[1,1].value.should_not == @old_cell_value3
|
366
366
|
new_book3.close
|
367
367
|
end
|
@@ -390,7 +390,7 @@ module RobustExcelOle
|
|
390
390
|
#@excel1 = book1.excel
|
391
391
|
@excel2 = book2.excel
|
392
392
|
#@excel4 = book4.excel
|
393
|
-
sheet2 = book2
|
393
|
+
sheet2 = book2.sheet(1)
|
394
394
|
@old_cell_value2 = sheet2[1,1].value
|
395
395
|
sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
|
396
396
|
#sheet3 = book3[0]
|
@@ -410,7 +410,7 @@ module RobustExcelOle
|
|
410
410
|
#@excel4.should_not be_alive
|
411
411
|
#@excel5.should_not be_alive
|
412
412
|
new_book2 = Book.open(@simple_file)
|
413
|
-
new_sheet2 = new_book2
|
413
|
+
new_sheet2 = new_book2.sheet(1)
|
414
414
|
new_sheet2[1,1].value.should_not == @old_cell_value2
|
415
415
|
new_book2.close
|
416
416
|
#new_book3 = Book.open(@another_simple_file)
|
@@ -428,7 +428,7 @@ module RobustExcelOle
|
|
428
428
|
#@excel4.should_not be_alive
|
429
429
|
#@excel5.should_not be_alive
|
430
430
|
new_book2 = Book.open(@simple_file)
|
431
|
-
new_sheet2 = new_book2
|
431
|
+
new_sheet2 = new_book2.sheet(1)
|
432
432
|
new_sheet2[1,1].value.should == @old_cell_value2
|
433
433
|
new_book2.close
|
434
434
|
#new_book4 = Book.open(@different_file)
|
@@ -472,11 +472,11 @@ module RobustExcelOle
|
|
472
472
|
before do
|
473
473
|
@excel = Excel.create
|
474
474
|
@book = Book.open(@simple_file)
|
475
|
-
sheet = @book
|
475
|
+
sheet = @book.sheet(1)
|
476
476
|
@old_cell_value = sheet[1,1].value
|
477
477
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
478
478
|
@book2 = Book.open(@another_simple_file)
|
479
|
-
sheet2 = @book2
|
479
|
+
sheet2 = @book2.sheet(1)
|
480
480
|
@old_cell_value2 = sheet2[1,1].value
|
481
481
|
sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
|
482
482
|
end
|
@@ -497,11 +497,11 @@ module RobustExcelOle
|
|
497
497
|
@excel.close(:if_unsaved => :forget)
|
498
498
|
@excel.should_not be_alive
|
499
499
|
new_book = Book.open(@simple_file)
|
500
|
-
new_sheet = new_book
|
500
|
+
new_sheet = new_book.sheet(1)
|
501
501
|
new_sheet[1,1].value.should == @old_cell_value
|
502
502
|
new_book.close
|
503
503
|
new_book2 = Book.open(@another_simple_file)
|
504
|
-
new_sheet2 = new_book2
|
504
|
+
new_sheet2 = new_book2.sheet(1)
|
505
505
|
new_sheet2[1,1].value.should == @old_cell_value2
|
506
506
|
new_book2.close
|
507
507
|
end
|
@@ -511,11 +511,11 @@ module RobustExcelOle
|
|
511
511
|
@excel.close(:if_unsaved => :save)
|
512
512
|
@excel.should_not be_alive
|
513
513
|
new_book = Book.open(@simple_file)
|
514
|
-
new_sheet = new_book
|
514
|
+
new_sheet = new_book.sheet(1)
|
515
515
|
new_sheet[1,1].value.should_not == @old_cell_value
|
516
516
|
new_book.close
|
517
517
|
new_book2 = Book.open(@another_simple_file)
|
518
|
-
new_sheet2 = new_book2
|
518
|
+
new_sheet2 = new_book2.sheet(1)
|
519
519
|
new_sheet2[1,1].value.should_not == @old_cell_value2
|
520
520
|
new_book2.close
|
521
521
|
end
|
@@ -548,7 +548,7 @@ module RobustExcelOle
|
|
548
548
|
@excel.should_not be_alive
|
549
549
|
@book.should_not be_alive
|
550
550
|
new_book = Book.open(@simple_file)
|
551
|
-
new_sheet = new_book
|
551
|
+
new_sheet = new_book.sheet(1)
|
552
552
|
new_sheet[1,1].value.should == @old_cell_value
|
553
553
|
new_book.close
|
554
554
|
new_book.excel.close(:hard => true)
|
@@ -568,7 +568,7 @@ module RobustExcelOle
|
|
568
568
|
@key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '/helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
|
569
569
|
@excel = Excel.create
|
570
570
|
@book = Book.open(@simple_file)
|
571
|
-
sheet = @book
|
571
|
+
sheet = @book.sheet(1)
|
572
572
|
@old_cell_value = sheet[1,1].value
|
573
573
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
574
574
|
end
|
@@ -584,7 +584,7 @@ module RobustExcelOle
|
|
584
584
|
@excel.close(:if_unsaved => :alert)
|
585
585
|
@excel.should_not be_alive
|
586
586
|
new_book = Book.open(@simple_file)
|
587
|
-
new_sheet = new_book
|
587
|
+
new_sheet = new_book.sheet(1)
|
588
588
|
new_sheet[1,1].value.should_not == @old_cell_value
|
589
589
|
new_book.close
|
590
590
|
end
|
@@ -598,7 +598,7 @@ module RobustExcelOle
|
|
598
598
|
@excel.should_not be_alive
|
599
599
|
@book.should_not be_alive
|
600
600
|
new_book = Book.open(@simple_file)
|
601
|
-
new_sheet = new_book
|
601
|
+
new_sheet = new_book.sheet(1)
|
602
602
|
new_sheet[1,1].value.should == @old_cell_value
|
603
603
|
new_book.close
|
604
604
|
end
|
@@ -736,6 +736,43 @@ module RobustExcelOle
|
|
736
736
|
@excel2.DisplayAlerts.should be_false
|
737
737
|
end
|
738
738
|
end
|
739
|
+
end
|
740
|
+
|
741
|
+
context "with calculation" do
|
742
|
+
|
743
|
+
before do
|
744
|
+
@excel1 = Excel.new(:visible => true)
|
745
|
+
end
|
746
|
+
|
747
|
+
it "should not set calculation mode when no workbook is opened" do
|
748
|
+
@excel1.with_calculation(:automatic) do
|
749
|
+
@excel1.Calculation.should_not == -4105
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
it "should set calculation mode to manual" do
|
754
|
+
b = Book.open(@simple_file)
|
755
|
+
@excel1.with_calculation(:manual) do
|
756
|
+
@excel1.Calculation.should == -4135
|
757
|
+
@excel1.CalculateBeforeSave.should be_false
|
758
|
+
end
|
759
|
+
end
|
760
|
+
|
761
|
+
it "should set calculation mode automatic" do
|
762
|
+
b = Book.open(@simple_file)
|
763
|
+
@excel1.with_calculation(:automatic) do
|
764
|
+
@excel1.Calculation.should == -4105
|
765
|
+
@excel1.CalculateBeforeSave.should be_true
|
766
|
+
end
|
767
|
+
end
|
768
|
+
|
769
|
+
it "should set calculation mode to automatic as default" do
|
770
|
+
b = Book.open(@simple_file)
|
771
|
+
@excel1.with_calculation do
|
772
|
+
@excel1.Calculation.should == -4105
|
773
|
+
@excel1.CalculateBeforeSave.should be_true
|
774
|
+
end
|
775
|
+
end
|
739
776
|
|
740
777
|
end
|
741
778
|
|
@@ -788,12 +825,12 @@ module RobustExcelOle
|
|
788
825
|
before do
|
789
826
|
@book = Book.open(@simple_file)
|
790
827
|
@book3 = Book.open(@different_file, :read_only => true)
|
791
|
-
sheet = @book
|
828
|
+
sheet = @book.sheet(1)
|
792
829
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
793
|
-
sheet3 = @book3
|
830
|
+
sheet3 = @book3.sheet(1)
|
794
831
|
sheet3[1,1] = sheet3[1,1].value == "foo" ? "bar" : "foo"
|
795
832
|
@book2 = Book.open(@another_simple_file, :force_excel => :new)
|
796
|
-
sheet2 = @book2
|
833
|
+
sheet2 = @book2.sheet(1)
|
797
834
|
sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
|
798
835
|
end
|
799
836
|
|
@@ -882,6 +919,120 @@ module RobustExcelOle
|
|
882
919
|
|
883
920
|
end
|
884
921
|
end
|
922
|
+
|
923
|
+
describe "nameval, set_nameval" do
|
924
|
+
|
925
|
+
before do
|
926
|
+
@book1 = Book.open(@dir + '/another_workbook.xls')
|
927
|
+
@excel1 = @book1.excel
|
928
|
+
end
|
929
|
+
|
930
|
+
after do
|
931
|
+
@book1.close(:if_unsaved => :forget)
|
932
|
+
end
|
933
|
+
|
934
|
+
it "should return value of a defined name" do
|
935
|
+
@excel1.nameval("firstcell").should == "foo"
|
936
|
+
@excel1["firstcell"].should == "foo"
|
937
|
+
end
|
938
|
+
|
939
|
+
it "should return default value if name not defined and default value is given" do
|
940
|
+
@excel1.nameval("foo", :default => 2).should == 2
|
941
|
+
end
|
942
|
+
|
943
|
+
it "should evaluate a formula" do
|
944
|
+
@excel1.nameval("named_formula").should == 4
|
945
|
+
@excel1["named_formula"].should == 4
|
946
|
+
end
|
947
|
+
|
948
|
+
it "should raise an error if name not defined" do
|
949
|
+
expect {
|
950
|
+
@excel1.nameval("foo")
|
951
|
+
}.to raise_error(ExcelError, /cannot find name "foo"/)
|
952
|
+
expect {
|
953
|
+
@excel1["foo"]
|
954
|
+
}.to raise_error(ExcelError, /cannot find name "foo"/)
|
955
|
+
expect {
|
956
|
+
excel2 = Excel.create
|
957
|
+
excel2.nameval("one")
|
958
|
+
}.to raise_error(ExcelError, /cannot find name "one"/)
|
959
|
+
expect {
|
960
|
+
excel3 = Excel.create
|
961
|
+
excel3["one"]
|
962
|
+
}.to raise_error(ExcelError, /cannot find name "one"/)
|
963
|
+
end
|
964
|
+
|
965
|
+
it "should set a range to a value" do
|
966
|
+
@excel1.nameval("firstcell").should == "foo"
|
967
|
+
@excel1.set_nameval("firstcell","bar")
|
968
|
+
@excel1.nameval("firstcell").should == "bar"
|
969
|
+
@excel1["firstcell"] = "foo"
|
970
|
+
@excel1.nameval("firstcell").should == "foo"
|
971
|
+
end
|
972
|
+
|
973
|
+
it "should raise an error if name cannot be evaluated" do
|
974
|
+
expect{
|
975
|
+
@excel1.set_nameval("foo", 1)
|
976
|
+
}.to raise_error(ExcelError, /cannot find name "foo"/)
|
977
|
+
expect{
|
978
|
+
@excel1["foo"] = 1
|
979
|
+
}.to raise_error(ExcelError, /cannot find name "foo"/)
|
980
|
+
end
|
981
|
+
end
|
982
|
+
|
983
|
+
describe "rangeval, set_rangeval" do
|
984
|
+
|
985
|
+
before do
|
986
|
+
@book1 = Book.open(@dir + '/another_workbook.xls')
|
987
|
+
@excel1 = @book1.excel
|
988
|
+
end
|
989
|
+
|
990
|
+
after do
|
991
|
+
@book1.close(:if_unsaved => :forget)
|
992
|
+
end
|
993
|
+
|
994
|
+
it "should return value of a locally defined name" do
|
995
|
+
@excel1.rangeval("firstcell").should == "foo"
|
996
|
+
end
|
997
|
+
|
998
|
+
it "should return value of a defined name" do
|
999
|
+
@excel1.rangeval("new").should == "foo"
|
1000
|
+
@excel1.rangeval("one").should == 1.0
|
1001
|
+
@excel1.rangeval("four").should == [[1,2],[3,4]]
|
1002
|
+
@excel1.rangeval("firstrow").should == [[1,2]]
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
it "should return default value if name not defined and default value is given" do
|
1006
|
+
@excel1.rangeval("foo", :default => 2).should == 2
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
it "should raise an error if name not defined for the sheet" do
|
1010
|
+
expect {
|
1011
|
+
@excel1.rangeval("foo")
|
1012
|
+
}.to raise_error(ExcelError, /cannot find name "foo"/)
|
1013
|
+
expect {
|
1014
|
+
@excel1.rangeval("named_formula")
|
1015
|
+
}.to raise_error(ExcelError, /cannot find name "named_formula"/)
|
1016
|
+
expect {
|
1017
|
+
excel2 = Excel.create
|
1018
|
+
excel2.rangeval("one")
|
1019
|
+
}.to raise_error(ExcelError, /cannot find name "one"/)
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
it "should set a range to a value" do
|
1023
|
+
@excel1.rangeval("firstcell").should == "foo"
|
1024
|
+
@excel1.set_rangeval("firstcell","bar")
|
1025
|
+
@excel1.rangeval("firstcell").should == "bar"
|
1026
|
+
end
|
1027
|
+
|
1028
|
+
it "should raise an error if name cannot be evaluated" do
|
1029
|
+
expect{
|
1030
|
+
@excel1.set_nameval("foo", 1)
|
1031
|
+
}.to raise_error(ExcelError, /cannot find name "foo"/)
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
end
|
1035
|
+
|
885
1036
|
end
|
886
1037
|
end
|
887
1038
|
|
data/spec/general_spec.rb
CHANGED
@@ -43,8 +43,8 @@ module RobustExcelOle
|
|
43
43
|
["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
|
44
44
|
"Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
|
45
45
|
"SaveAs", "Saved", "Sheets", "Unprotect"]
|
46
|
-
@book_methods = ["activate", "add_sheet", "alive?", "close", "filename", "
|
47
|
-
"ole_workbook", "reopen", "save", "save_as", "saved", "
|
46
|
+
@book_methods = ["activate", "add_sheet", "alive?", "close", "filename", "nameval", "ole_object",
|
47
|
+
"ole_workbook", "reopen", "save", "save_as", "saved", "set_nameval"]
|
48
48
|
@ole_excel_methods =
|
49
49
|
["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
|
50
50
|
"DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
|
@@ -161,7 +161,7 @@ module RobustExcelOle
|
|
161
161
|
|
162
162
|
before do
|
163
163
|
@book = Book.open(@simple_file)
|
164
|
-
@sheet = @book
|
164
|
+
@sheet = @book.sheet(1)
|
165
165
|
end
|
166
166
|
|
167
167
|
before do
|
@@ -173,21 +173,6 @@ module RobustExcelOle
|
|
173
173
|
@sheet.excel
|
174
174
|
}.to raise_error(ExcelError, "receiver instance is neither an Excel nor a Book")
|
175
175
|
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
describe "trace" do
|
180
|
-
|
181
|
-
it "should put some number" do
|
182
|
-
a = 4
|
183
|
-
trace "some text #{a}"
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should put another text" do
|
187
|
-
a = 5
|
188
|
-
trace "another text #{a}"
|
189
|
-
end
|
190
176
|
end
|
191
|
-
|
192
177
|
end
|
193
178
|
end
|
data/spec/range_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe RobustExcelOle::Range do
|
|
15
15
|
before do
|
16
16
|
@dir = create_tmpdir
|
17
17
|
@book = Book.open(@dir + '/workbook.xls', :force_excel => :new)
|
18
|
-
@sheet = @book
|
18
|
+
@sheet = @book.sheet(2)
|
19
19
|
@range = RobustExcelOle::Range.new(@sheet.worksheet.UsedRange.Rows(1))
|
20
20
|
end
|
21
21
|
|
@@ -52,7 +52,7 @@ describe RobustExcelOle::Range do
|
|
52
52
|
|
53
53
|
context "when instance is column range" do
|
54
54
|
before do
|
55
|
-
@sheet = @book
|
55
|
+
@sheet = @book.sheet(1)
|
56
56
|
@range = RobustExcelOle::Range.new(@sheet.worksheet.UsedRange.Columns(1))
|
57
57
|
end
|
58
58
|
it { @range.values.should eq ['foo', 'foo', 'matz'] }
|
@@ -61,7 +61,7 @@ describe RobustExcelOle::Range do
|
|
61
61
|
context "read 'merge_cells.xls'" do
|
62
62
|
before do
|
63
63
|
@merge_cells_book = Book.open("#{@dir}/merge_cells.xls", :force_excel => :new)
|
64
|
-
@merge_cells_sheet = @merge_cells_book
|
64
|
+
@merge_cells_sheet = @merge_cells_book.sheet(1)
|
65
65
|
end
|
66
66
|
|
67
67
|
after do
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), './spec_helper')
|
4
|
+
require File.expand_path( '../../lib/robust_excel_ole/reo_common', __FILE__)
|
5
|
+
|
6
|
+
$VERBOSE = nil
|
7
|
+
|
8
|
+
include General
|
9
|
+
include RobustExcelOle
|
10
|
+
|
11
|
+
module RobustExcelOle
|
12
|
+
|
13
|
+
describe REOCommon do
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
excel = Excel.new(:reuse => true)
|
17
|
+
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
18
|
+
puts "*** open books *** : #{open_books}" if open_books > 0
|
19
|
+
Excel.kill_all
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
@dir = create_tmpdir
|
24
|
+
@simple_file = @dir + '/workbook.xls'
|
25
|
+
@simple_save_file = @dir + '/workbook_save.xls'
|
26
|
+
@different_file = @dir + '/different_workbook.xls'
|
27
|
+
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
28
|
+
@another_simple_file = @dir + '/another_workbook.xls'
|
29
|
+
@linked_file = @dir + '/workbook_linked.xlsm'
|
30
|
+
@simple_file_xlsm = @dir + '/workbook.xls'
|
31
|
+
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
Excel.kill_all
|
36
|
+
rm_tmp(@dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "trace" do
|
40
|
+
|
41
|
+
it "should put some number" do
|
42
|
+
a = 4
|
43
|
+
REOCommon::trace "some text #{a}"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should put another text" do
|
47
|
+
b = Book.open(@simple_file)
|
48
|
+
REOCommon::trace "book: #{b}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "own_methods" do
|
53
|
+
|
54
|
+
before do
|
55
|
+
@book1 = Book.open(@simple_file)
|
56
|
+
@ole_workbook_methods =
|
57
|
+
["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
|
58
|
+
"Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
|
59
|
+
"SaveAs", "Saved", "Sheets", "Unprotect"]
|
60
|
+
@book_methods = ["activate", "add_sheet", "alive?", "close", "filename", "nameval", "ole_object",
|
61
|
+
"ole_workbook", "reopen", "save", "save_as", "saved", "set_nameval"]
|
62
|
+
@ole_excel_methods =
|
63
|
+
["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
|
64
|
+
"DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
|
65
|
+
"Sheets", "UserName", "Value", "Visible", "Workbooks", "Worksheets"]
|
66
|
+
@excel_methods = ["alive?", "book_class", "close", "displayalerts", "recreate", "visible", "with_displayalerts"]
|
67
|
+
end
|
68
|
+
|
69
|
+
after do
|
70
|
+
@book1.close
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should do own_methods with popular ole_workbook and workbook methods" do
|
74
|
+
((@ole_workbook_methods + @book_methods) - @book1.own_methods).should be_empty
|
75
|
+
(Object.instance_methods - @book1.own_methods).should == Object.instance_methods
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should do own_methods with popular ole_excel and excel methods" do
|
79
|
+
((@ole_excel_methods + @excel_methods) - @book1.excel.own_methods).should be_empty
|
80
|
+
(Object.instance_methods - @book1.excel.own_methods).should == Object.instance_methods
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Object methods" do
|
86
|
+
|
87
|
+
before do
|
88
|
+
@book = Book.open(@simple_file)
|
89
|
+
@sheet = @book.sheet(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
before do
|
93
|
+
@book.close
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should raise an error when asking excel of a sheet" do
|
97
|
+
expect{
|
98
|
+
@sheet.excel
|
99
|
+
}.to raise_error(ExcelError, "receiver instance is neither an Excel nor a Book")
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|