Open untoldone opened 4 years ago
Seeing this issue as well. This is not expected behavior for ruby to change an objects reference like that. If this is the desired behavior of this method it should be changed to sheet! and the documentation updated to reflect what happens when you call this method.
@untoldone, It happens because the method .sheet changes the default sheet and returns the default sheet. And when you call it two times you will have the last sheet in two variables (sheet1 and sheet2). The behavior really looks like a bug. You can fix it fast by opening the document two times (create a two instance of a class):
require "roo"
xlsx1 = Roo::Excelx.new("/Users/untoldone/Downloads/UDS-2019-Full-Dataset.xlsx")
xlsx2 = Roo::Excelx.new("/Users/untoldone/Downloads/UDS-2019-Full-Dataset.xlsx")
sheet1 = xlsx1.sheet("HealthCenterSiteInfo")
sheet2 = xlsx2.sheet("HealthCenterInfo")
puts sheet1.row(1)
Thanks for filing an issue. Following these instructions will help us solve your problem sooner.
Steps to reproduce
In case this is file specific, the above
UDS-2019-Full-Dataset.xlsx
file can be found at https://www.hrsa.gov/sites/default/files/hrsa/foia/UDS-2019-Full-Dataset.xlsxIssue
The above code outputs row 1 of the sheet titled "HealthCenterInfo". My expected behavior is that it would output the first row of the sheet titled "HealthCenterSiteInfo".
It is possible I misunderstood how the API was intended to behave and perhaps you can only have one sheet "open" at a time... but given the way the API is structured my expectation would be that a reference to a sheet does not change which sheet its pointing at once created. If this is the expected behavior, then I would describe this issue as a documentation issue as this behavior isn't clear given the current documentation.
System configuration
Roo version: 2.8.3
Ruby version: 2.6.6p146