Skip to content

Commit

Permalink
Merge pull request #495 from md5/merge_cells-allow-row
Browse files Browse the repository at this point in the history
Allow a Row to be passed to merge_cells
  • Loading branch information
randym committed Nov 3, 2016
2 parents b1f78e7 + 97bea6e commit b7b65c0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/axlsx/workbook/worksheet/merged_cells.rb
Expand Up @@ -19,6 +19,8 @@ def add(cells)
cells
elsif cells.is_a?(Array)
Axlsx::cell_range(cells, false)
elsif cells.is_a?(Row)
Axlsx::cell_range(cells, false)
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/tc_axlsx.rb
Expand Up @@ -45,6 +45,16 @@ def test_cell_range_absolute
assert_equal(Axlsx.cell_range([c2, c1], true), "'Sheet <''>" 1'!$A$1:$B$1")
end

def test_cell_range_row
p = Axlsx::Package.new
ws = p.workbook.add_worksheet
row = ws.add_row
c1 = row.add_cell
c2 = row.add_cell
c3 = row.add_cell
assert_equal("A1:C1", Axlsx.cell_range(row, false))
end

def test_name_to_indices
setup_wide
@wide_test_points.each do |key, value|
Expand Down
7 changes: 7 additions & 0 deletions test/workbook/worksheet/tc_worksheet.rb
Expand Up @@ -323,6 +323,13 @@ def test_to_xml_string_merge_cells
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size, 1)
end

def test_to_xml_string_merge_cells_row
row = @ws.add_row [1, "two"]
@ws.merge_cells row
doc = Nokogiri::XML(@ws.to_xml_string)
assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:B1"]').size, 1)
end

def test_to_xml_string_row_breaks
@ws.add_page_break("A1")
doc = Nokogiri::XML(@ws.to_xml_string)
Expand Down

0 comments on commit b7b65c0

Please sign in to comment.