robust_excel_ole 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog +13 -0
  3. data/README.rdoc +107 -73
  4. data/{README_excel.rdoc → docs/README_excel.rdoc} +2 -0
  5. data/{README_open.rdoc → docs/README_open.rdoc} +12 -16
  6. data/{README_ranges.rdoc → docs/README_ranges.rdoc} +1 -1
  7. data/{README_save_close.rdoc → docs/README_save_close.rdoc} +0 -0
  8. data/{README_sheet.rdoc → docs/README_sheet.rdoc} +0 -0
  9. data/examples/open_save_close/example_control_to_excel.rb +3 -3
  10. data/examples/open_save_close/example_default_excel.rb +2 -2
  11. data/examples/open_save_close/example_force_excel.rb +2 -2
  12. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
  13. data/examples/open_save_close/example_if_obstructed_forget.rb +2 -2
  14. data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
  15. data/examples/open_save_close/example_if_unsaved_accept.rb +3 -3
  16. data/examples/open_save_close/example_if_unsaved_forget.rb +7 -3
  17. data/examples/open_save_close/example_if_unsaved_forget_more.rb +1 -1
  18. data/examples/open_save_close/example_read_only.rb +2 -2
  19. data/examples/open_save_close/example_rename_cells.rb +2 -2
  20. data/examples/open_save_close/example_reuse.rb +2 -2
  21. data/examples/open_save_close/example_simple.rb +1 -1
  22. data/examples/open_save_close/example_unobtrusively.rb +2 -2
  23. data/lib/robust_excel_ole/book.rb +75 -76
  24. data/lib/robust_excel_ole/bookstore.rb +9 -9
  25. data/lib/robust_excel_ole/excel.rb +5 -5
  26. data/lib/robust_excel_ole/general.rb +11 -4
  27. data/lib/robust_excel_ole/reo_common.rb +3 -0
  28. data/lib/robust_excel_ole/version.rb +1 -1
  29. data/robust_excel_ole.gemspec +2 -2
  30. data/spec/book_spec.rb +67 -63
  31. data/spec/book_specs/book_close_spec.rb +12 -10
  32. data/spec/book_specs/book_misc_spec.rb +279 -279
  33. data/spec/book_specs/book_open_spec.rb +258 -105
  34. data/spec/book_specs/book_save_spec.rb +28 -28
  35. data/spec/book_specs/book_unobtr_spec.rb +862 -164
  36. data/spec/bookstore_spec.rb +22 -22
  37. data/spec/data/another_workbook.xls +0 -0
  38. data/spec/data/different_workbook.xls +0 -0
  39. data/spec/data/workbook.xls +0 -0
  40. data/spec/excel_spec.rb +256 -254
  41. data/spec/general_spec.rb +7 -7
  42. data/spec/ruby1.8.6_rspec2.14/book_spec.rb +1421 -0
  43. data/spec/ruby1.8.6_rspec2.14/book_specs/book_all_spec.rb +22 -0
  44. data/spec/ruby1.8.6_rspec2.14/book_specs/book_close_spec.rb +252 -0
  45. data/spec/ruby1.8.6_rspec2.14/book_specs/book_misc_spec.rb +1070 -0
  46. data/spec/ruby1.8.6_rspec2.14/book_specs/book_open_spec.rb +1855 -0
  47. data/spec/ruby1.8.6_rspec2.14/book_specs/book_save_spec.rb +514 -0
  48. data/spec/ruby1.8.6_rspec2.14/book_specs/book_sheet_spec.rb +395 -0
  49. data/spec/ruby1.8.6_rspec2.14/book_specs/book_subclass_spec.rb +51 -0
  50. data/spec/ruby1.8.6_rspec2.14/book_specs/book_unobtr_spec.rb +1737 -0
  51. data/spec/ruby1.8.6_rspec2.14/bookstore_spec.rb +495 -0
  52. data/spec/ruby1.8.6_rspec2.14/cell_spec.rb +76 -0
  53. data/spec/ruby1.8.6_rspec2.14/cygwin_spec.rb +42 -0
  54. data/spec/ruby1.8.6_rspec2.14/excel_spec.rb +1820 -0
  55. data/spec/ruby1.8.6_rspec2.14/general_spec.rb +212 -0
  56. data/spec/ruby1.8.6_rspec2.14/range_spec.rb +131 -0
  57. data/spec/ruby1.8.6_rspec2.14/reo_common_spec.rb +130 -0
  58. data/spec/ruby1.8.6_rspec2.14/sheet_spec.rb +663 -0
  59. data/spec/ruby1.8.6_rspec2.14/spec_helper.rb +35 -0
  60. data/spec/sheet_spec.rb +2 -2
  61. metadata +28 -12
  62. data/README_detail.rdoc +0 -852
  63. data/README_development.rdoc +0 -5
@@ -0,0 +1,212 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), './spec_helper')
4
+
5
+ $VERBOSE = nil
6
+
7
+ include General
8
+ include RobustExcelOle
9
+
10
+ module RobustExcelOle
11
+
12
+ describe General do
13
+
14
+ before(:all) do
15
+ excel = Excel.new(:reuse => true)
16
+ open_books = excel == nil ? 0 : excel.Workbooks.Count
17
+ puts "*** open books *** : #{open_books}" if open_books > 0
18
+ Excel.kill_all
19
+ end
20
+
21
+ before do
22
+ @dir = create_tmpdir
23
+ @simple_file = @dir + '/workbook.xls'
24
+ @simple_save_file = @dir + '/workbook_save.xls'
25
+ @different_file = @dir + '/different_workbook.xls'
26
+ @simple_file_other_path = @dir + '/more_data/workbook.xls'
27
+ @another_simple_file = @dir + '/another_workbook.xls'
28
+ @linked_file = @dir + '/workbook_linked.xlsm'
29
+ @simple_file_xlsm = @dir + '/workbook.xls'
30
+ @simple_file_xlsx = @dir + '/workbook.xlsx'
31
+ end
32
+
33
+ after do
34
+ Excel.kill_all
35
+ rm_tmp(@dir)
36
+ end
37
+
38
+ describe "methods, own_methods, respond_to?" do
39
+
40
+ before do
41
+ @book1 = Book.open(@simple_file)
42
+ @ole_workbook_methods =
43
+ ["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
44
+ "Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
45
+ "SaveAs", "Saved", "Sheets", "Unprotect"]
46
+ @book_methods = ["focus", "add_sheet", "alive?", "close", "filename", "nameval", "ole_object",
47
+ "ole_workbook", "reopen", "save", "save_as", "saved", "set_nameval"]
48
+ @ole_excel_methods =
49
+ ["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
50
+ "DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
51
+ "Sheets", "UserName", "Value", "Visible", "Workbooks", "Worksheets"]
52
+ @excel_methods = ["alive?", "book_class", "close", "displayalerts", "recreate", "visible",
53
+ "with_displayalerts"]
54
+ @ole_sheet_methods = []
55
+ # ["Activate", "Calculate", "Copy", "Name", "Select", "Evaluate", "Protect", "Unprotect"]
56
+ @sheet_methods = ["book_class", "col_range", "each", "each_column", "each_column_with_index",
57
+ "each_row", "each_row_with_index", "nameval", "rangeval",
58
+ "set_rangeval", "row_range", "set_nameval"]
59
+ end
60
+
61
+ after do
62
+ @book1.close
63
+ end
64
+
65
+ it "should do methods for book" do
66
+ ((@ole_workbook_methods + @book_methods) - @book1.methods).should be_empty
67
+ (Object.instance_methods.select{|m| m =~ /^(?!\_)/} - @book1.methods).should be_empty
68
+ end
69
+
70
+ it "should do own_methods with popular ole_workbook and workbook methods" do
71
+ ((@ole_workbook_methods + @book_methods) - @book1.own_methods).should be_empty
72
+ (Object.instance_methods - @book1.own_methods).should == Object.instance_methods
73
+ end
74
+
75
+ it "should respond to popular workbook methods" do
76
+ @book_methods.each{|m| @book1.respond_to?(m).should be_true}
77
+ end
78
+
79
+ it "should do methods for excel" do
80
+ ((@ole_excel_methods + @excel_methods) - @book1.excel.methods).should be_empty
81
+ (Object.instance_methods.select{|m| m =~ /^(?!\_)/} - @book1.excel.methods).sort.should be_empty
82
+ end
83
+
84
+ it "should do own_methods with popular ole_excel and excel methods" do
85
+ ((@ole_excel_methods + @excel_methods) - @book1.excel.own_methods).should be_empty
86
+ (Object.instance_methods - @book1.excel.own_methods).should == Object.instance_methods
87
+ end
88
+
89
+ it "should respond to popular excel methods" do
90
+ @excel_methods.each{|m| @book1.excel.respond_to?(m).should be_true}
91
+ end
92
+
93
+ it "should do methods for sheet" do
94
+ ((@ole_sheet_methods + @sheet_methods) - @book1.sheet(1).methods).should be_empty
95
+ (Object.instance_methods.select{|m| m =~ /^(?!\_)/} - @book1.sheet(1).methods).sort.should be_empty
96
+ end
97
+
98
+ it "should do own_methods with popular ole_excel and excel methods" do
99
+ ((@ole_sheet_methods + @sheet_methods) - @book1.sheet(1).own_methods).should == [] #be_empty
100
+ (Object.instance_methods - @book1.sheet(1).own_methods).should == Object.instance_methods
101
+ end
102
+
103
+ it "should respond to popular sheet methods" do
104
+ @sheet_methods.each{|m| @book1.sheet(1).respond_to?(m).should be_true}
105
+ end
106
+
107
+ end
108
+
109
+ describe "#absolute_path" do
110
+
111
+ context "with standard" do
112
+
113
+ before do
114
+ @previous_dir = Dir.getwd
115
+ end
116
+
117
+ after do
118
+ Dir.chdir @previous_dir
119
+ end
120
+
121
+ it "should return the right absolute paths" do
122
+ absolute_path("C:/abc").should == "C:\\abc"
123
+ absolute_path("C:\\abc").should == "C:\\abc"
124
+ Dir.chdir "C:/windows"
125
+ absolute_path("C:abc").downcase.should == Dir.pwd.gsub("/","\\").downcase + "\\abc"
126
+ absolute_path("C:abc").upcase.should == File.expand_path("abc").gsub("/","\\").upcase
127
+ end
128
+
129
+ it "should return right absolute path name" do
130
+ filename = 'C:/Dokumente und Einstellungen/Zauberthomas/Eigene Dateien/robust_excel_ole/spec/book_spec.rb'
131
+ absolute_path(filename).gsub("\\","/").should == filename
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "canonize" do
137
+
138
+ context "with standard" do
139
+
140
+ it "should reduce slash at the end" do
141
+ normalize("hallo/").should == "hallo"
142
+ normalize("/this/is/the/Path/").should == "/this/is/the/Path"
143
+ end
144
+
145
+ it "should save capital letters" do
146
+ normalize("HALLO/").should == "HALLO"
147
+ normalize("/This/IS/tHe/patH/").should == "/This/IS/tHe/patH"
148
+ end
149
+
150
+ it "should reduce multiple shlashes" do
151
+ normalize("/this/is//the/path").should == "/this/is/the/path"
152
+ normalize("///this/////////is//the/path/////").should == "/this/is/the/path"
153
+ end
154
+
155
+ it "should reduce dots in the paths" do
156
+ canonize("/this/is/./the/path").should == "/this/is/the/path"
157
+ canonize("this/.is/./the/pa.th/").should == "this/.is/the/pa.th"
158
+ canonize("this//.///.//.is/the/pa.th/").should == "this/.is/the/pa.th"
159
+ end
160
+
161
+ it "should change to the upper directory with two dots" do
162
+ canonize("/this/is/../the/path").should == "/this/the/path"
163
+ canonize("this../.i.s/.../..the/..../pa.th/").should == "this../.i.s/.../..the/..../pa.th"
164
+ end
165
+
166
+ it "should downcase" do
167
+ canonize("/This/IS/tHe/path").should == "/this/is/the/path"
168
+ canonize("///THIS/.///./////iS//the/../PatH/////").should == "/this/is/path"
169
+ end
170
+
171
+ it "should raise an error for no strings" do
172
+ expect{
173
+ canonize(1)
174
+ }.to raise_error(TypeREOError, "No string given to canonize, but 1")
175
+ end
176
+
177
+ end
178
+ end
179
+
180
+ describe "path" do
181
+
182
+ it "should create a path" do
183
+ path1 = "this" / "is" / "a" / "path"
184
+ path1.should == "this/is/a/path"
185
+ path2 = "this" / "is" / "a" / "path" /
186
+ #path2.should == "this/is/a/path/"
187
+ path3 = "this" /
188
+ #path3.should == "this/"
189
+ path4 = "this" / nil
190
+ path4.should == "this"
191
+ end
192
+ end
193
+
194
+ describe "Object methods" do
195
+
196
+ before do
197
+ @book = Book.open(@simple_file)
198
+ @sheet = @book.sheet(1)
199
+ end
200
+
201
+ before do
202
+ @book.close
203
+ end
204
+
205
+ it "should raise an error when asking excel of a sheet" do
206
+ expect{
207
+ @sheet.excel
208
+ }.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a Book")
209
+ end
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,131 @@
1
+ # -*- cdoing: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), './spec_helper')
3
+
4
+ include RobustExcelOle
5
+
6
+ describe RobustExcelOle::Range do
7
+
8
+ before(:all) do
9
+ excel = Excel.new(:reuse => true)
10
+ open_books = excel == nil ? 0 : excel.Workbooks.Count
11
+ puts "*** open books *** : #{open_books}" if open_books > 0
12
+ Excel.kill_all
13
+ end
14
+
15
+ before do
16
+ @dir = create_tmpdir
17
+ @book = Book.open(@dir + '/workbook.xls', :force_excel => :new)
18
+ @sheet = @book.sheet(2)
19
+ @range = RobustExcelOle::Range.new(@sheet.ole_worksheet.UsedRange.Rows(1))
20
+ end
21
+
22
+ after do
23
+ @book.close
24
+ Excel.kill_all
25
+ rm_tmp(@dir)
26
+ end
27
+
28
+ describe "#each" do
29
+ it "items is RobustExcelOle::Cell" do
30
+ @range.each do |cell|
31
+ cell.should be_kind_of RobustExcelOle::Cell
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#values" do
37
+ context "with (0..2)" do
38
+ it { @range.values(0..2).should eq ['simple', 'file', 'sheet2'] }
39
+ end
40
+
41
+ context "with (1..2)" do
42
+ it { @range.values(1..2).should eq ['file', 'sheet2'] }
43
+ end
44
+
45
+ context "with (2..2)" do
46
+ it { @range.values(2..2).should eq ['sheet2'] }
47
+ end
48
+
49
+ context "with no arguments" do
50
+ it { @range.values.should eq ['simple', 'file', 'sheet2'] }
51
+ end
52
+
53
+ context "when instance is column range" do
54
+ before do
55
+ @sheet = @book.sheet(1)
56
+ @range = RobustExcelOle::Range.new(@sheet.ole_worksheet.UsedRange.Columns(1))
57
+ end
58
+ it { @range.values.should eq ['foo', 'foo', 'matz'] }
59
+ end
60
+
61
+ context "read 'merge_cells.xls'" do
62
+ before do
63
+ @merge_cells_book = Book.open("#{@dir}/merge_cells.xls", :force_excel => :new)
64
+ @merge_cells_sheet = @merge_cells_book.sheet(1)
65
+ end
66
+
67
+ after do
68
+ @merge_cells_book.close
69
+ end
70
+
71
+ context "only merged_cell" do
72
+ before do
73
+ @only_merged_range = @merge_cells_sheet.row_range(4)
74
+ end
75
+
76
+ context "without argument" do
77
+ it { @only_merged_range.values.should eq ['merged', 'merged', 'merged', 'merged'] }
78
+ end
79
+
80
+ context "with (1..2)" do
81
+ it { @only_merged_range.values(2..3).should eq ['merged', 'merged'] }
82
+ end
83
+
84
+ end
85
+
86
+ context "mix merged cell and no merge cell" do
87
+ before do
88
+ @mix_merged_no_merged_range = @merge_cells_sheet.row_range(2)
89
+ end
90
+
91
+ context "without argument" do
92
+ it { @mix_merged_no_merged_range.values.should eq ['first merged', 'first merged', 'first merged', nil] }
93
+ end
94
+
95
+ context "with (2..3)" do
96
+ it { @mix_merged_no_merged_range.values(2..3).should eq ['first merged', nil] }
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "#[]" do
104
+ context "access [0]" do
105
+ it { @range[0].should be_kind_of RobustExcelOle::Cell }
106
+ it { @range[0].value.should eq 'simple' }
107
+ end
108
+
109
+ context "access [2]" do
110
+ it { @range[2].value.should eq 'sheet2' }
111
+ end
112
+
113
+ context "access [0] and [1] and [2]" do
114
+ it "should get every values" do
115
+ @range[0].value.should eq 'simple'
116
+ @range[1].value.should eq 'file'
117
+ @range[2].value.should eq 'sheet2'
118
+ end
119
+ end
120
+ end
121
+
122
+ describe "#method_missing" do
123
+ it "can access COM method" do
124
+ @range.Range(@range.Cells.Item(1), @range.Cells.Item(3)).value.should eq [@range.values(0..2)]
125
+ end
126
+
127
+ context "unknown method" do
128
+ it { expect { @range.hogehogefoo}.to raise_error }
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,130 @@
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
+ it "should simple test" do
16
+ puts "a"
17
+ end
18
+
19
+ before(:all) do
20
+ excel = Excel.new(:reuse => true)
21
+ open_books = excel == nil ? 0 : excel.Workbooks.Count
22
+ puts "*** open books *** : #{open_books}" if open_books > 0
23
+ Excel.kill_all
24
+ end
25
+
26
+ before do
27
+ @dir = create_tmpdir
28
+ @simple_file = @dir + '/workbook.xls'
29
+ @simple_save_file = @dir + '/workbook_save.xls'
30
+ @different_file = @dir + '/different_workbook.xls'
31
+ @simple_file_other_path = @dir + '/more_data/workbook.xls'
32
+ @another_simple_file = @dir + '/another_workbook.xls'
33
+ @linked_file = @dir + '/workbook_linked.xlsm'
34
+ @simple_file_xlsm = @dir + '/workbook.xls'
35
+ @simple_file_xlsx = @dir + '/workbook.xlsx'
36
+ end
37
+
38
+ after do
39
+ Excel.kill_all
40
+ #rm_tmp(@dir)
41
+ end
42
+
43
+ describe "trace" do
44
+
45
+ it "should put some number" do
46
+ a = 4
47
+ REOCommon::trace "some text #{a}"
48
+ end
49
+
50
+ it "should put another text" do
51
+ b = Book.open(@simple_file)
52
+ REOCommon::trace "book: #{b}"
53
+ end
54
+ end
55
+
56
+ describe "own_methods" do
57
+
58
+ before do
59
+ @book1 = Book.open(@simple_file)
60
+ @ole_workbook_methods =
61
+ ["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
62
+ "Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
63
+ "SaveAs", "Saved", "Sheets", "Unprotect"]
64
+ @book_methods = ["focus", "add_sheet", "alive?", "close", "filename", "nameval", "ole_object",
65
+ "ole_workbook", "reopen", "save", "save_as", "saved", "set_nameval"]
66
+ @ole_excel_methods =
67
+ ["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
68
+ "DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
69
+ "Sheets", "UserName", "Value", "Visible", "Workbooks", "Worksheets"]
70
+ @excel_methods = ["alive?", "book_class", "close", "displayalerts", "recreate", "visible", "with_displayalerts"]
71
+ end
72
+
73
+ after do
74
+ @book1.close
75
+ end
76
+
77
+ it "should do own_methods with popular ole_workbook and workbook methods" do
78
+ ((@ole_workbook_methods + @book_methods) - @book1.own_methods).should be_empty
79
+ (Object.instance_methods - @book1.own_methods).should == Object.instance_methods
80
+ end
81
+
82
+ it "should do own_methods with popular ole_excel and excel methods" do
83
+ ((@ole_excel_methods + @excel_methods) - @book1.excel.own_methods).should be_empty
84
+ (Object.instance_methods - @book1.excel.own_methods).should == Object.instance_methods
85
+ end
86
+
87
+ end
88
+
89
+ describe "Object methods" do
90
+
91
+ before do
92
+ @book = Book.open(@simple_file)
93
+ @sheet = @book.sheet(1)
94
+ end
95
+
96
+ before do
97
+ @book.close
98
+ end
99
+
100
+ it "should raise an error when asking excel of a sheet" do
101
+ expect{
102
+ @sheet.excel
103
+ }.to raise_error(TypeREOError, "receiver instance is neither an Excel nor a Book")
104
+ end
105
+
106
+ end
107
+
108
+ describe "misc" do
109
+
110
+ LOG_TO_STDOUT = true
111
+ REOCommon::trace "foo"
112
+
113
+ LOG_TO_STDOUT = false
114
+ REOCommon::trace "foo"
115
+
116
+ REO_LOG_DIR = ""
117
+ REOCommon::trace "foo"
118
+
119
+ REO_LOG_DIR = "C:"
120
+ REOCommon::trace "foo"
121
+
122
+ REOCommon::tr1 "foo"
123
+
124
+ h = {:a => {:c => 4}, :b => 2}
125
+ REOCommon::puts_hash(h)
126
+
127
+ end
128
+
129
+ end
130
+ end