Class: WrapExcel::Sheet
- Inherits:
-
Object
show all
- Includes:
- Enumerable
- Defined in:
- lib/wrap_excel/sheet.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(win32_worksheet) ⇒ Sheet
Returns a new instance of Sheet.
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/wrap_excel/sheet.rb', line 7
def initialize(win32_worksheet)
@sheet = win32_worksheet
if @sheet.ProtectContents
@sheet.Unprotect
@end_row = last_row
@end_column = last_column
@sheet.Protect
else
@end_row = last_row
@end_column = last_column
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args) ⇒ Object
84
85
86
|
# File 'lib/wrap_excel/sheet.rb', line 84
def method_missing(id, *args)
@sheet.send(id, *args)
end
|
Instance Attribute Details
#sheet ⇒ Object
Returns the value of attribute sheet.
4
5
6
|
# File 'lib/wrap_excel/sheet.rb', line 4
def sheet
@sheet
end
|
Instance Method Details
#[](y, x) ⇒ Object
28
29
30
31
32
|
# File 'lib/wrap_excel/sheet.rb', line 28
def [] y, x
yx = "#{y+1}_#{x+1}"
@cells ||= { }
@cells[yx] ||= WrapExcel::Cell.new(@sheet.Cells.Item(y+1, x+1))
end
|
#[]=(y, x, value) ⇒ Object
34
35
36
|
# File 'lib/wrap_excel/sheet.rb', line 34
def []= (y, x, value)
@sheet.Cells.Item(y+1, x+1).Value = value
end
|
#col_range(col, range = nil) ⇒ Object
79
80
81
82
|
# File 'lib/wrap_excel/sheet.rb', line 79
def col_range(col, range = nil)
range ||= 0..@end_row - 1
WrapExcel::Range.new(@sheet.Range(@sheet.Cells(range.min + 1, col + 1), @sheet.Cells(range.max + 1, col + 1)))
end
|
#each ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/wrap_excel/sheet.rb', line 38
def each
each_row do |row_range|
row_range.each do |cell|
yield cell
end
end
end
|
#each_column(offset = 0) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/wrap_excel/sheet.rb', line 60
def each_column(offset = 0)
offset += 1
1.upto(@end_column) do |column|
next if column < offset
yield WrapExcel::Range.new(@sheet.Range(@sheet.Cells(1, column), @sheet.Cells(@end_row, column)))
end
end
|
#each_column_with_index(offset = 0) ⇒ Object
68
69
70
71
72
|
# File 'lib/wrap_excel/sheet.rb', line 68
def each_column_with_index(offset = 0)
each_column(offset) do |column_range|
yield WrapExcel::Range.new(column_range), (column_range.column - 1 - offset)
end
end
|
#each_row(offset = 0) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/wrap_excel/sheet.rb', line 46
def each_row(offset = 0)
offset += 1
1.upto(@end_row) do |row|
next if row < offset
yield WrapExcel::Range.new(@sheet.Range(@sheet.Cells(row, 1), @sheet.Cells(row, @end_column)))
end
end
|
#each_row_with_index(offset = 0) ⇒ Object
54
55
56
57
58
|
# File 'lib/wrap_excel/sheet.rb', line 54
def each_row_with_index(offset = 0)
each_row(offset) do |row_range|
yield WrapExcel::Range.new(row_range), (row_range.row - 1 - offset)
end
end
|
#name ⇒ Object
20
21
22
|
# File 'lib/wrap_excel/sheet.rb', line 20
def name
@sheet.Name
end
|
#name=(new_name) ⇒ Object
24
25
26
|
# File 'lib/wrap_excel/sheet.rb', line 24
def name= (new_name)
@sheet.Name = new_name
end
|
#row_range(row, range = nil) ⇒ Object
74
75
76
77
|
# File 'lib/wrap_excel/sheet.rb', line 74
def row_range(row, range = nil)
range ||= 0..@end_column - 1
WrapExcel::Range.new(@sheet.Range(@sheet.Cells(row + 1, range.min + 1), @sheet.Cells(row + 1, range.max + 1)))
end
|