Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implied coordinates #549

Merged
merged 2 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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