Created
June 9, 2014 18:49
-
-
Save zverok/f2a639291d9e4905e1ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cell | |
def self.parse(sheet, name) | |
if name =~ /([A-Za-z]+)([0-9]+)/ | |
raise(ArgumentError, "Exceeds the maximum number columns (256 columns): #{top_left_cell.inspect}") unless COLUMNS.index($1) | |
new(sheet, COLUMNS.index($1), $2.to_i - 1) | |
end | |
end | |
def initialize(sheet, c, r) | |
@sheet, @c, @r = sheet, c, r | |
end | |
def offset(offset = {}) | |
Cell.new(sheet, c + offset[:c].to_i, r + offset[:r].to_i) | |
end | |
def name | |
"#{COLUMNS[c]}#{r+1}" | |
end | |
def to_s | |
name | |
end | |
def set(value) | |
# переносим сюда код set_cell | |
end | |
def range(data) | |
data.each_with_index do |row, dr| | |
row.each_with_index do |value, dc| | |
offset(r: dr, c: dc).set(value) | |
end | |
end | |
end | |
end | |
# в ExcelHelpers | |
def cell(name) | |
Cell.parse(current_sheet, name) | |
end | |
# Использование: | |
cell('A1').range [[1,2,3], [4,5,6]] | |
cell('A2').offset(r: 3).range .... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment