rubyXL: Worksheet#dimension problem and more
Just ran across this file a few days ago and figured, that Worksheet#dimension method, instead of returning a neat set of dimensions (like it usually does), gave me this:
=> #<RubyXL::WorksheetDimensions:0x007fc0abb59f78 @ref=#<RubyXL::Reference @row=486 @col=15>>
whereas normally it would return
=> #<RubyXL::WorksheetDimensions:0x007fc0b93ea388 @ref=#<RubyXL::Reference @row_range=0..486 @col_range=0..14>>
While exploring the file that caused the problem I found that dimension element (the one in worksheets/sheet1.xml from which RubyXL probably takes the value) is written out like this:
<dimension ref="P487"/>
I went on to read the specification (ECMA Office Open XML Part 1) and found that in §18.3.1.35 it’s saying that the element is “optional and is not required”.
To solve my problem (ie to get the dimensions) I used this workaround:
row_idxs, col_idxs = [], []
worksheet.sheet.sheet_data.rows.compact.each do |row|
row.cells.compact.each do |cell|
row_idxs << cell.row
col_idxs << cell.column
end
end
# In case worksheet is totally empty
row_idxs << 0 if row_idxs.empty?
col_idxs << 0 if col_idxs.empty?
[row_idxs.min, row_idxs.max, col_idxs.min, col_idxs.max]
And then in a minute I learned that
worksheet[13][1].value # should return the text value from row 14, column 2
returned an empty string instead of “г. Сходня, ул. Первомайская (от М10 к г. Сходня 0+550м) право, B” which is actually contained in the cell.
I checked the inner contents of the xlsx file again and found all the strings in _rels/SharedStrings.xml. Re-saving the file solves the problem, but unfortunately I cannot do this in production.
All in all, this is the problem of the software that creates the file, but Excel itself opens it ok. Shouldn’t RubyXL do so, too?
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 18 (9 by maintainers)
Just a short update on the issue, my case-insensitivity modification was accepted to RubyZip (https://github.com/rubyzip/rubyzip/pull/222).