Fix Cell#r_abs to handle multi-digit row numbers and multi-letter column ids. #49

Merged
merged 2 commits into from Mar 12, 2012
Jump to file or symbol
Failed to load files and symbols.
+4 −1
Diff settings

Always

Just for now

@@ -230,7 +230,7 @@ def r
# @example Absolute Cell Reference
# ws.rows.first.cells.first.r #=> "$A$1"
def r_abs
- "$#{r.split('').join('$')}"
+ "$#{r.match(%r{([A-Z]+)([0-9]+)})[1,2].join('$')}"
end
# @return [Integer] The cellXfs item index applied to this cell.
@@ -9,6 +9,8 @@ def setup
p.workbook.styles.add_style :sz=>20
@row = @ws.add_row
@c = @row.add_cell 1, :type=>:float, :style=>1
+ @ws.add_row (0..26).map { |index| index }
+ @cAA = @ws["AA2"]
end
def test_initialize
@@ -42,6 +44,7 @@ def test_r
def test_r_abs
assert_equal(@c.r_abs,"$A$1", "calculate absolute cell reference")
+ assert_equal(@cAA.r_abs,"$AA$2", "needs to accept multi-digit columns")
end
def test_style