wrap_excel 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +10 -0
- data/README.ja.rdoc +8 -8
- data/README.rdoc +7 -7
- data/lib/wrap_excel/book.rb +1 -0
- data/lib/wrap_excel/sheet.rb +22 -9
- data/lib/wrap_excel/version.rb +1 -1
- data/spec/cell_spec.rb +7 -0
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/protected_sheet.xls +0 -0
- data/spec/range_spec.rb +10 -0
- data/spec/sheet_spec.rb +106 -0
- data/wrap_excel.gemspec +4 -0
- metadata +56 -7
data/Guardfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# A sample Guardfile
|
3
|
+
# More info at https://github.com/guard/guard#readme
|
4
|
+
|
5
|
+
guard 'rspec', :version => 2 do
|
6
|
+
watch(%r{^spec/.+_spec\.rb$})
|
7
|
+
watch(%r{^lib/wrap_excel/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
8
|
+
watch('lib/wrap_excel.rb') { "spec" }
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
data/README.ja.rdoc
CHANGED
@@ -28,13 +28,13 @@ WrapExcelはwin32oleをラップし、rubyによるExcelオペレーションを
|
|
28
28
|
|
29
29
|
オプションは以下の通りです。
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
[read_only] boolean(default true)
|
32
|
+
[displayalerts] boolean(default false)
|
33
|
+
[visible] boolean(default false)
|
34
34
|
|
35
35
|
=== sheetへのアクセス
|
36
36
|
|
37
|
-
sheetオブジェクトへは #[] メソッドでアクセス出来ます。
|
37
|
+
sheetオブジェクトへは Book#[] メソッドでアクセス出来ます。
|
38
38
|
|
39
39
|
sheet = book[0]
|
40
40
|
|
@@ -44,7 +44,7 @@ sheetオブジェクトへは #[] メソッドでアクセス出来ます。
|
|
44
44
|
|
45
45
|
=== 行または列へのアクセス
|
46
46
|
|
47
|
-
sheetオブジェクトはenumerable
|
47
|
+
sheetオブジェクトはenumerableをインクルードしています。Sheet#each_column or Sheet#each_row or Sheet#each メソッドが使用できます。
|
48
48
|
|
49
49
|
sheet.each do |cell|
|
50
50
|
# do something with cell
|
@@ -93,7 +93,7 @@ rangeオブジェクトからのアクセス。
|
|
93
93
|
|
94
94
|
== サポート
|
95
95
|
|
96
|
-
問題を報告したり、機能追加の要望する場合はgithubのIssuesに登録してください。
|
96
|
+
問題を報告したり、機能追加の要望する場合はgithubのIssuesに登録してください。 https://github.com/tomiacannondale/wrap_excel/issues
|
97
97
|
|
98
98
|
== 共同作業
|
99
99
|
|
@@ -101,8 +101,8 @@ githubのpull requestをしてください。
|
|
101
101
|
|
102
102
|
== 開発者
|
103
103
|
|
104
|
-
tomi
|
104
|
+
tomi mailto:tomiacannondale@gmail.com
|
105
105
|
|
106
106
|
== ライセンス
|
107
107
|
|
108
|
-
MITライセンスです。詳細はLICENSEを参照してください。
|
108
|
+
MITライセンスです。詳細は LICENSE を参照してください。
|
data/README.rdoc
CHANGED
@@ -28,13 +28,13 @@ Read without block.
|
|
28
28
|
|
29
29
|
Options are the following.
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
[read_only] boolean(default true)
|
32
|
+
[displayalerts] boolean(default false)
|
33
|
+
[visible] boolean(default false)
|
34
34
|
|
35
35
|
=== access sheet
|
36
36
|
|
37
|
-
Sheet object can access with #[] method.
|
37
|
+
Sheet object can access with Book#[] method.
|
38
38
|
|
39
39
|
sheet = book[0]
|
40
40
|
|
@@ -44,7 +44,7 @@ Access with sheet name.
|
|
44
44
|
|
45
45
|
=== access row or column
|
46
46
|
|
47
|
-
Sheet object is included enumerable. Use #each_column or #each_row or #each method.
|
47
|
+
Sheet object is included enumerable. Use Sheet#each_column or Sheet#each_row or Sheet#each method.
|
48
48
|
|
49
49
|
sheet.each do |cell|
|
50
50
|
# do something with cell
|
@@ -93,7 +93,7 @@ All WrapExcel object include win32ole instance. If you want to do something that
|
|
93
93
|
|
94
94
|
== Support
|
95
95
|
|
96
|
-
Report issues and feature requests to github Issues.
|
96
|
+
Report issues and feature requests to github Issues. https://github.com/tomiacannondale/wrap_excel/issues
|
97
97
|
|
98
98
|
== Collaborate
|
99
99
|
|
@@ -101,7 +101,7 @@ Please pull request on github.
|
|
101
101
|
|
102
102
|
== Author
|
103
103
|
|
104
|
-
tomi
|
104
|
+
tomi mailto:tomiacannondale@gmail.com
|
105
105
|
|
106
106
|
== License
|
107
107
|
|
data/lib/wrap_excel/book.rb
CHANGED
@@ -15,6 +15,7 @@ module WrapExcel
|
|
15
15
|
@winapp = WIN32OLE.new('Excel.Application')
|
16
16
|
@winapp.DisplayAlerts = options[:displayalerts]
|
17
17
|
@winapp.Visible = options[:visible]
|
18
|
+
WIN32OLE.const_load(@winapp, WrapExcel) unless WrapExcel.const_defined?(:CONSTANTS)
|
18
19
|
@book = @winapp.Workbooks.Open(file,{ 'ReadOnly' => options[:read_only] })
|
19
20
|
|
20
21
|
if block
|
data/lib/wrap_excel/sheet.rb
CHANGED
@@ -6,6 +6,15 @@ module WrapExcel
|
|
6
6
|
|
7
7
|
def initialize(win32_worksheet)
|
8
8
|
@sheet = win32_worksheet
|
9
|
+
if @sheet.ProtectContents
|
10
|
+
@sheet.Unprotect
|
11
|
+
@end_row = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Row
|
12
|
+
@end_column = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Column
|
13
|
+
@sheet.Protect
|
14
|
+
else
|
15
|
+
@end_row = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Row
|
16
|
+
@end_column = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Column
|
17
|
+
end
|
9
18
|
end
|
10
19
|
|
11
20
|
def name
|
@@ -27,18 +36,18 @@ module WrapExcel
|
|
27
36
|
end
|
28
37
|
|
29
38
|
def each
|
30
|
-
|
31
|
-
row_range.
|
32
|
-
yield
|
39
|
+
each_row do |row_range|
|
40
|
+
row_range.each do |cell|
|
41
|
+
yield cell
|
33
42
|
end
|
34
43
|
end
|
35
44
|
end
|
36
45
|
|
37
46
|
def each_row(offset = 0)
|
38
47
|
offset += 1
|
39
|
-
@
|
40
|
-
next if
|
41
|
-
yield WrapExcel::Range.new(
|
48
|
+
1.upto(@end_row) do |row|
|
49
|
+
next if row < offset
|
50
|
+
yield WrapExcel::Range.new(@sheet.Range(@sheet.Cells(row, 1), @sheet.Cells(row, @end_column)))
|
42
51
|
end
|
43
52
|
end
|
44
53
|
|
@@ -50,9 +59,9 @@ module WrapExcel
|
|
50
59
|
|
51
60
|
def each_column(offset = 0)
|
52
61
|
offset += 1
|
53
|
-
@
|
54
|
-
next if
|
55
|
-
yield WrapExcel::Range.new(
|
62
|
+
1.upto(@end_column) do |column|
|
63
|
+
next if column < offset
|
64
|
+
yield WrapExcel::Range.new(@sheet.Range(@sheet.Cells(1, column), @sheet.Cells(@end_row, column)))
|
56
65
|
end
|
57
66
|
end
|
58
67
|
|
@@ -61,5 +70,9 @@ module WrapExcel
|
|
61
70
|
yield WrapExcel::Range.new(column_range), (column_range.column - 1 - offset)
|
62
71
|
end
|
63
72
|
end
|
73
|
+
|
74
|
+
def method_missing(id, *args)
|
75
|
+
@sheet.send(id, *args)
|
76
|
+
end
|
64
77
|
end
|
65
78
|
end
|
data/lib/wrap_excel/version.rb
CHANGED
data/spec/cell_spec.rb
CHANGED
@@ -33,6 +33,13 @@ describe WrapExcel::Cell do
|
|
33
33
|
@cell.value.should eq 'fooooo'
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
describe "#method_missing" do
|
38
|
+
context "unknown method" do
|
39
|
+
it { expect { @cell.hogehogefoo }.to raise_error }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
36
43
|
end
|
37
44
|
|
38
45
|
context "open merge_cells.xls" do
|
Binary file
|
Binary file
|
data/spec/range_spec.rb
CHANGED
@@ -66,4 +66,14 @@ describe WrapExcel::Range do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
describe "#method_missing" do
|
71
|
+
it "can access COM method" do
|
72
|
+
@range.Range(@range.Cells.Item(1), @range.Cells.Item(3)).value.should eq [@range.values(0..2)]
|
73
|
+
end
|
74
|
+
|
75
|
+
context "unknown method" do
|
76
|
+
it { expect { @range.hogehogefoo}.to raise_error }
|
77
|
+
end
|
78
|
+
end
|
69
79
|
end
|
data/spec/sheet_spec.rb
CHANGED
@@ -13,6 +13,37 @@ describe WrapExcel::Sheet do
|
|
13
13
|
rm_tmp(@dir)
|
14
14
|
end
|
15
15
|
|
16
|
+
describe ".initialize" do
|
17
|
+
context "when open sheet protected(with password is 'protect')" do
|
18
|
+
before do
|
19
|
+
@book_protect = WrapExcel::Book.new(@dir + '/protected_sheet.xls', :visible => true)
|
20
|
+
@protected_sheet = @book_protect['protect']
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
@book_protect.close
|
25
|
+
end
|
26
|
+
|
27
|
+
it { @protected_sheet.ProtectContents.should be_true }
|
28
|
+
|
29
|
+
it "protected sheet can't be write" do
|
30
|
+
expect { @protected_sheet[0,0] = 'write' }.to raise_error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
shared_context "sheet 'open book with blank'" do
|
37
|
+
before do
|
38
|
+
@book_with_blank = WrapExcel::Book.open(@dir + '/book_with_blank.xls')
|
39
|
+
@sheet_with_blank = @book_with_blank[0]
|
40
|
+
end
|
41
|
+
|
42
|
+
after do
|
43
|
+
@book_with_blank.close
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
16
47
|
describe "access sheet name" do
|
17
48
|
describe "#name" do
|
18
49
|
it 'get sheet1 name' do
|
@@ -68,6 +99,28 @@ describe WrapExcel::Sheet do
|
|
68
99
|
end
|
69
100
|
end
|
70
101
|
end
|
102
|
+
|
103
|
+
context "read sheet with blank" do
|
104
|
+
include_context "sheet 'open book with blank'"
|
105
|
+
|
106
|
+
it 'should get from ["A1"]' do
|
107
|
+
@sheet_with_blank.each_with_index do |cell, i|
|
108
|
+
case i
|
109
|
+
when 5
|
110
|
+
cell.value.should be_nil
|
111
|
+
when 6
|
112
|
+
cell.value.should eq 'simple'
|
113
|
+
when 7
|
114
|
+
cell.value.should be_nil
|
115
|
+
when 8
|
116
|
+
cell.value.should eq 'workbook'
|
117
|
+
when 9
|
118
|
+
cell.value.should eq 'sheet1'
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
71
124
|
end
|
72
125
|
|
73
126
|
describe "#each_row" do
|
@@ -89,6 +142,28 @@ describe WrapExcel::Sheet do
|
|
89
142
|
end
|
90
143
|
end
|
91
144
|
end
|
145
|
+
|
146
|
+
context "read sheet with blank" do
|
147
|
+
include_context "sheet 'open book with blank'"
|
148
|
+
|
149
|
+
it 'should get from ["A1"]' do
|
150
|
+
@sheet_with_blank.each_row do |rows|
|
151
|
+
case rows.row - 1
|
152
|
+
when 0
|
153
|
+
rows.values.should eq [nil, nil, nil, nil, nil]
|
154
|
+
when 1
|
155
|
+
rows.values.should eq [nil, 'simple', nil, 'workbook', 'sheet1']
|
156
|
+
when 2
|
157
|
+
rows.values.should eq [nil, 'foo', nil, nil, 'foobaaa']
|
158
|
+
when 3
|
159
|
+
rows.values.should eq [nil, nil, nil, nil, nil]
|
160
|
+
when 4
|
161
|
+
rows.values.should eq [nil, 'matz', nil, 'is', 'nice']
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
92
167
|
end
|
93
168
|
|
94
169
|
describe "#each_row_with_index" do
|
@@ -139,6 +214,27 @@ describe WrapExcel::Sheet do
|
|
139
214
|
end
|
140
215
|
end
|
141
216
|
end
|
217
|
+
|
218
|
+
context "read sheet with blank" do
|
219
|
+
include_context "sheet 'open book with blank'"
|
220
|
+
|
221
|
+
it 'should get from ["A1"]' do
|
222
|
+
@sheet_with_blank.each_column do |columns|
|
223
|
+
case columns.column- 1
|
224
|
+
when 0
|
225
|
+
columns.values.should eq [nil, nil, nil, nil, nil]
|
226
|
+
when 1
|
227
|
+
columns.values.should eq [nil, 'simple', 'foo', nil, 'matz']
|
228
|
+
when 2
|
229
|
+
columns.values.should eq [nil, nil, nil, nil, nil]
|
230
|
+
when 3
|
231
|
+
columns.values.should eq [nil, 'workbook', nil, nil, 'is']
|
232
|
+
when 4
|
233
|
+
columns.values.should eq [nil, 'sheet1', 'foobaaa', nil, 'nice']
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
142
238
|
end
|
143
239
|
|
144
240
|
describe "#each_column_with_index" do
|
@@ -169,5 +265,15 @@ describe WrapExcel::Sheet do
|
|
169
265
|
end
|
170
266
|
end
|
171
267
|
|
268
|
+
describe "#method_missing" do
|
269
|
+
it "can access COM method" do
|
270
|
+
@sheet.Cells(1,1).Value.should eq 'simple'
|
271
|
+
end
|
272
|
+
|
273
|
+
context "unknown method" do
|
274
|
+
it { expect { @sheet.hogehogefoo }.to raise_error }
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
172
278
|
end
|
173
279
|
end
|
data/wrap_excel.gemspec
CHANGED
@@ -25,4 +25,8 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.require_paths = ["lib"]
|
26
26
|
s.add_development_dependency "rake", '>= 0.9.2'
|
27
27
|
s.add_development_dependency "rspec", '>= 2.6.0'
|
28
|
+
s.add_development_dependency "rb-fchange"
|
29
|
+
s.add_development_dependency "rb-notifu"
|
30
|
+
s.add_development_dependency "win32console"
|
31
|
+
s.add_development_dependency "guard-rspec"
|
28
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrap_excel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &25478484 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *25478484
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &25494132 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,51 @@ dependencies:
|
|
32
32
|
version: 2.6.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *25494132
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rb-fchange
|
38
|
+
requirement: &25493820 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *25493820
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rb-notifu
|
49
|
+
requirement: &25493496 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *25493496
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: win32console
|
60
|
+
requirement: &25493172 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *25493172
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: &25492884 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *25492884
|
36
80
|
description: WrapExcel is to wrap the win32ole, and easy to use Excel operations with
|
37
81
|
ruby. Detailed description please see the README.
|
38
82
|
email:
|
@@ -47,6 +91,7 @@ files:
|
|
47
91
|
- .gitignore
|
48
92
|
- .rspec
|
49
93
|
- Gemfile
|
94
|
+
- Guardfile
|
50
95
|
- LICENSE
|
51
96
|
- README.ja.rdoc
|
52
97
|
- README.rdoc
|
@@ -60,7 +105,9 @@ files:
|
|
60
105
|
- spec/book_spec.rb
|
61
106
|
- spec/cell_spec.rb
|
62
107
|
- spec/cygwin_spec.rb
|
108
|
+
- spec/data/book_with_blank.xls
|
63
109
|
- spec/data/merge_cells.xls
|
110
|
+
- spec/data/protected_sheet.xls
|
64
111
|
- spec/data/simple.xls
|
65
112
|
- spec/range_spec.rb
|
66
113
|
- spec/sheet_spec.rb
|
@@ -90,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
137
|
version: '0'
|
91
138
|
requirements: []
|
92
139
|
rubyforge_project: wrap_excel
|
93
|
-
rubygems_version: 1.8.
|
140
|
+
rubygems_version: 1.8.11
|
94
141
|
signing_key:
|
95
142
|
specification_version: 3
|
96
143
|
summary: WrapExcel is a wrapper library that specializes in the operation of Excel
|
@@ -99,7 +146,9 @@ test_files:
|
|
99
146
|
- spec/book_spec.rb
|
100
147
|
- spec/cell_spec.rb
|
101
148
|
- spec/cygwin_spec.rb
|
149
|
+
- spec/data/book_with_blank.xls
|
102
150
|
- spec/data/merge_cells.xls
|
151
|
+
- spec/data/protected_sheet.xls
|
103
152
|
- spec/data/simple.xls
|
104
153
|
- spec/range_spec.rb
|
105
154
|
- spec/sheet_spec.rb
|