summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-03-01 21:43:19 +0900
committerRandy Morgan <[email protected]>2012-03-01 21:43:19 +0900
commitf1c563b2d59aa123e5a42e2afaae568b149584f7 (patch)
tree411e6530ea237952d912de64090aa836216d8969
parentd06b14cf31eb92bff1895df612e70fd0608c3822 (diff)
parentd4d72ffc179b4ce7d8694acd1f0a1ac6337e14d6 (diff)
downloadcaxlsx-f1c563b2d59aa123e5a42e2afaae568b149584f7.tar.gz
caxlsx-f1c563b2d59aa123e5a42e2afaae568b149584f7.zip
Merge https://github.com/randym/axlsx
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb5
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb4
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index cd0c6c97..68a3e3c6 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -112,9 +112,10 @@ module Axlsx
# Returns the cell or cells defined using excel style A1:B3 references.
- # @param [String] cell_def the string defining the cell or range of cells
+ # @param [String|Integer] cell_def the string defining the cell or range of cells, or the rownumber
# @return [Cell, Array]
def [](cell_def)
+ return rows[cell_def - 1] if cell_def.is_a? Integer
parts = cell_def.split(':')
first = name_to_cell parts[0]
@@ -234,6 +235,8 @@ module Axlsx
yield @rows.last if block_given?
@rows.last
end
+
+ alias :<< :add_row
# Set the style for cells in a specific row
# @param [Integer] index or range of indexes in the table
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index ac71fce3..97845c92 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -62,6 +62,10 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [1, 2, 3]
@ws.add_row [4, 5, 6]
range = @ws["A1:C2"]
+ first_row = @ws[1]
+ last_row = @ws[2]
+ assert_equal(@ws.rows[0],first_row)
+ assert_equal(@ws.rows[1],last_row)
assert_equal(range.size, 6)
assert_equal(range.first, @ws.rows.first.cells.first)
assert_equal(range.last, @ws.rows.last.cells.last)