Skip to content
Open
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
4 changes: 3 additions & 1 deletion lib/roo/excelx/sheet_doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def each_row_streaming(&block)
# Yield each cell as Excelx::Cell to caller for given
# row xml
def each_cell(row_xml)
return to_enum(:each_cell, row_xml) unless block_given?

return [] unless row_xml
row_xml.children.each do |cell_element|
coordinate = ::Roo::Utils.extract_coordinate(cell_element["r"])
Expand Down Expand Up @@ -111,7 +113,7 @@ def cell_from_xml(cell_xml, hyperlink, coordinate, empty_cell=true)
format = style_format(style)
value_type = cell_value_type(cell_xml["t"], format)

return create_cell_from_value(value_type, cell, formula, format, style, hyperlink, coordinate)
return create_cell_from_value(value_type, cell, formula, format, style, hyperlink, coordinate) unless cell.content.empty?
end
end

Expand Down
23 changes: 23 additions & 0 deletions spec/lib/roo/excelx/sheet_doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,27 @@
example "#last_row" do
expect(subject.last_row).to eq 3
end

describe "#each_cell" do
let(:relationships) { instance_double(Roo::Excelx::Relationships, include_type?: false) }
let(:styles) { instance_double(Roo::Excelx::Styles, style_format: 'General') }
let(:shared) { instance_double(Roo::Excelx::Shared, styles: styles) }
let(:sheet_doc) { described_class.new(nil, relationships, shared) }

context "empty v element" do
let(:row_xml) { Nokogiri.parse('<row r="1"><c r="A1"><v/></c></row>').root }

it "returns an empty cell" do
expect(sheet_doc.each_cell(row_xml)).to all(be_a(Roo::Excelx::Cell::Empty))
end
end

context "no v element" do
let(:row_xml) { Nokogiri.parse('<row r="1"><c r="A1"></c></row>').root }

it "returns an empty cell" do
expect(sheet_doc.each_cell(row_xml)).to all(be_a(Roo::Excelx::Cell::Empty))
end
end
end
end