Skip to content

Commit

Permalink
Merge pull request #549 from TermSync/implied_coordinates
Browse files Browse the repository at this point in the history
Implied coordinates
  • Loading branch information
simonoff authored Mar 19, 2022
2 parents ddec0cb + 5eb8a8a commit 0aaf0d5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/roo/excelx/sheet_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,19 @@ def extract_cells(relationships)
extracted_cells = {}
empty_cell = @options[:empty_cell]

doc.xpath('/worksheet/sheetData/row/c').each do |cell_xml|
coordinate = ::Roo::Utils.extract_coordinate(cell_xml["r"])
cell = cell_from_xml(cell_xml, hyperlinks(relationships)[coordinate], coordinate, empty_cell)
extracted_cells[coordinate] = cell if cell
doc.xpath('/worksheet/sheetData/row').each.with_index(1) do |row_xml, ycoord|
row_xml.xpath('c').each.with_index(1) do |cell_xml, xcoord|
r = cell_xml['r']
coordinate =
if r.nil?
::Roo::Excelx::Coordinate.new(ycoord, xcoord)
else
::Roo::Utils.extract_coordinate(r)
end

cell = cell_from_xml(cell_xml, hyperlinks(relationships)[coordinate], coordinate, empty_cell)
extracted_cells[coordinate] = cell if cell
end
end

expand_merged_ranges(extracted_cells) if @options[:expand_merged_ranges]
Expand Down
Binary file added test/files/implicit_coordinates.xlsx
Binary file not shown.
9 changes: 9 additions & 0 deletions test/roo/test_excelx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ def test_parsing_xlsx_with_richtext
assert_equal "Example richtext", xlsx.cell("b", 1)
end

def test_implicit_coordinates
xlsx = roo_class.new(File.join(TESTDIR, 'implicit_coordinates.xlsx'))

assert_equal 'Test', xlsx.cell('a', 1)
assert_equal 'A2', xlsx.cell('a', 2)
assert_equal 'B2', xlsx.cell(2, 2)
assert_equal 'C2', xlsx.cell('c', 2)
end

def roo_class
Roo::Excelx
end
Expand Down

0 comments on commit 0aaf0d5

Please sign in to comment.