Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Worksheet#merge_cells sometimes produced invalid merge ranges when gi…
…ven an array of cells.

Merging e.g. cells A9 and A10 resulted in invalid range "A10:A9".
  • Loading branch information
noniq committed May 15, 2012
1 parent 9237511 commit 80252d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/axlsx/workbook/worksheet/worksheet.rb
Expand Up @@ -204,7 +204,7 @@ def merge_cells(cells)
@merged_cells << if cells.is_a?(String)
cells
elsif cells.is_a?(Array)
cells = cells.sort { |x, y| x.r <=> y.r }
cells = cells.sort { |x, y| [x.index, x.row.index] <=> [y.index, y.row.index] }
"#{cells.first.r}:#{cells.last.r}"
end
end
Expand Down
10 changes: 9 additions & 1 deletion test/workbook/worksheet/tc_worksheet.rb
Expand Up @@ -382,7 +382,15 @@ def test_merge_cells
assert_equal(@ws.merged_cells.size, 3)
assert_equal(@ws.merged_cells.last, "A3:B3")
end


def test_merge_cells_sorts_correctly_by_row_when_given_array
10.times do |i|
@ws.add_row [i]
end
@ws.merge_cells [@ws.rows[8].cells.first, @ws.rows[9].cells.first]
assert_equal "A9:A10", @ws.merged_cells.first
end

def test_auto_filter
assert(@ws.auto_filter.nil?)
assert_raise(ArgumentError) { @ws.auto_filter = 123 }
Expand Down

0 comments on commit 80252d1

Please sign in to comment.