diff --git a/lib/roo/excelx/sheet_doc.rb b/lib/roo/excelx/sheet_doc.rb index adbb77a8..7a09725a 100755 --- a/lib/roo/excelx/sheet_doc.rb +++ b/lib/roo/excelx/sheet_doc.rb @@ -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] diff --git a/test/files/implicit_coordinates.xlsx b/test/files/implicit_coordinates.xlsx new file mode 100644 index 00000000..039d0187 Binary files /dev/null and b/test/files/implicit_coordinates.xlsx differ diff --git a/test/roo/test_excelx.rb b/test/roo/test_excelx.rb index 61161f07..c90cd8c0 100644 --- a/test/roo/test_excelx.rb +++ b/test/roo/test_excelx.rb @@ -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