wrap_excel 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  vendor/bundle
6
6
  *~
7
+ .DS_Store
@@ -14,14 +14,8 @@ module WrapExcel
14
14
  end
15
15
 
16
16
  def values(range = nil)
17
- if range
18
- min = range.min + 1
19
- max = range.max + 1
20
- result = @range.Range(@range.Cells.Item(min), @range.Cells(max)).value
21
- result.is_a?(Array) ? result[0] : [result]
22
- else
23
- @range.Cells.value.flatten
24
- end
17
+ result = self.map(&:value).flatten
18
+ range ? result.each_with_index.select{ |row_or_column, i| range.include?(i) }.map{ |i| i[0] } : result
25
19
  end
26
20
 
27
21
  def [] index
@@ -8,12 +8,12 @@ module WrapExcel
8
8
  @sheet = win32_worksheet
9
9
  if @sheet.ProtectContents
10
10
  @sheet.Unprotect
11
- @end_row = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Row
12
- @end_column = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Column
11
+ @end_row = last_row
12
+ @end_column = last_column
13
13
  @sheet.Protect
14
14
  else
15
- @end_row = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Row
16
- @end_column = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Column
15
+ @end_row = last_row
16
+ @end_column = last_column
17
17
  end
18
18
  end
19
19
 
@@ -84,5 +84,20 @@ module WrapExcel
84
84
  def method_missing(id, *args)
85
85
  @sheet.send(id, *args)
86
86
  end
87
+
88
+ private
89
+ def last_row
90
+ special_last_row = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Row
91
+ used_last_row = @sheet.UsedRange.Rows.Count
92
+
93
+ special_last_row >= used_last_row ? special_last_row : used_last_row
94
+ end
95
+
96
+ def last_column
97
+ special_last_column = @sheet.UsedRange.SpecialCells(WrapExcel::XlLastCell).Column
98
+ used_last_column = @sheet.UsedRange.Columns.Count
99
+
100
+ special_last_column >= used_last_column ? special_last_column : used_last_column
101
+ end
87
102
  end
88
103
  end
@@ -1,3 +1,3 @@
1
1
  module WrapExcel
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/spec/cell_spec.rb CHANGED
@@ -53,8 +53,8 @@ describe WrapExcel::Cell do
53
53
  end
54
54
 
55
55
  it "merged cell get same value" do
56
- @sheet[0, 0].value.should eq 'merged cell'
57
- @sheet[0, 1].value.should eq 'merged cell'
56
+ @sheet[0, 0].value.should be_nil
57
+ @sheet[1, 0].value.should eq 'first merged'
58
58
  end
59
59
 
60
60
  it "set merged cell" do
Binary file
data/spec/range_spec.rb CHANGED
@@ -46,6 +46,47 @@ describe WrapExcel::Range do
46
46
  end
47
47
  it { @range.values.should eq ['simple', 'foo', 'matz'] }
48
48
  end
49
+
50
+ context "read 'merge_cells.xls'" do
51
+ before do
52
+ @merge_cells_book = WrapExcel::Book.open("#{@dir}/merge_cells.xls")
53
+ @merge_cells_sheet = @merge_cells_book[0]
54
+ end
55
+
56
+ after do
57
+ @merge_cells_book.close
58
+ end
59
+
60
+ context "only merged_cell" do
61
+ before do
62
+ @only_merged_range = @merge_cells_sheet.row_range(3)
63
+ end
64
+
65
+ context "without argument" do
66
+ it { @only_merged_range.values.should eq ['merged', 'merged', 'merged', 'merged'] }
67
+ end
68
+
69
+ context "with (1..2)" do
70
+ it { @only_merged_range.values(1..2).should eq ['merged', 'merged'] }
71
+ end
72
+
73
+ end
74
+
75
+ context "mix merged cell and no merge cell" do
76
+ before do
77
+ @mix_merged_no_merged_range = @merge_cells_sheet.row_range(1)
78
+ end
79
+
80
+ context "without argument" do
81
+ it { @mix_merged_no_merged_range.values.should eq ['first merged', 'first merged', 'first merged', nil] }
82
+ end
83
+
84
+ context "with (2..3)" do
85
+ it { @mix_merged_no_merged_range.values(2..3).should eq ['first merged', nil] }
86
+ end
87
+
88
+ end
89
+ end
49
90
  end
50
91
 
51
92
  describe "#[]" do
data/spec/sheet_spec.rb CHANGED
@@ -235,6 +235,32 @@ describe WrapExcel::Sheet do
235
235
  end
236
236
  end
237
237
  end
238
+
239
+ context "read sheet which last cell is merged" do
240
+ before do
241
+ @book_merge_cells = WrapExcel::Book.open(@dir + '/merge_cells.xls')
242
+ @sheet_merge_cell = @book_merge_cells[0]
243
+ end
244
+
245
+ after do
246
+ @book_merge_cells.close
247
+ end
248
+
249
+ it "should get from ['A1'] to ['C2']" do
250
+ columns_values = []
251
+ @sheet_merge_cell.each_column do |columns|
252
+ columns_values << columns.values
253
+ end
254
+ columns_values.should eq [
255
+ [nil, 'first merged', nil, 'merged'],
256
+ [nil, 'first merged', 'first', 'merged'],
257
+ [nil, 'first merged', 'second', 'merged'],
258
+ [nil, nil, 'third', 'merged']
259
+ ]
260
+ end
261
+
262
+ end
263
+
238
264
  end
239
265
 
240
266
  describe "#each_column_with_index" do
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.7
4
+ version: 0.0.8
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: 2012-03-09 00:00:00.000000000 Z
12
+ date: 2012-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &19519968 !ruby/object:Gem::Requirement
16
+ requirement: &21104316 !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: *19519968
24
+ version_requirements: *21104316
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &19519620 !ruby/object:Gem::Requirement
27
+ requirement: &21103752 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.6.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *19519620
35
+ version_requirements: *21103752
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rb-fchange
38
- requirement: &19535736 !ruby/object:Gem::Requirement
38
+ requirement: &21103380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *19535736
46
+ version_requirements: *21103380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rb-notifu
49
- requirement: &19535400 !ruby/object:Gem::Requirement
49
+ requirement: &21102828 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *19535400
57
+ version_requirements: *21102828
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: win32console
60
- requirement: &19535124 !ruby/object:Gem::Requirement
60
+ requirement: &21102420 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *19535124
68
+ version_requirements: *21102420
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &19534608 !ruby/object:Gem::Requirement
71
+ requirement: &21102036 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *19534608
79
+ version_requirements: *21102036
80
80
  description: WrapExcel is to wrap the win32ole, and easy to use Excel operations with
81
81
  ruby. Detailed description please see the README.
82
82
  email:
@@ -132,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  segments:
134
134
  - 0
135
- hash: 703779037
135
+ hash: 767876733
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  none: false
138
138
  requirements:
@@ -141,10 +141,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: 703779037
144
+ hash: 767876733
145
145
  requirements: []
146
146
  rubyforge_project: wrap_excel
147
- rubygems_version: 1.8.11
147
+ rubygems_version: 1.8.16
148
148
  signing_key:
149
149
  specification_version: 3
150
150
  summary: WrapExcel is a wrapper library that specializes in the operation of Excel