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

Sheet references are not stable while calling other API... either issue or docs issue #550

Open
untoldone opened this issue Nov 9, 2020 · 2 comments

Comments

@untoldone
Copy link

Thanks for filing an issue. Following these instructions will help us solve your problem sooner.

Steps to reproduce

require "roo"

xlsx = Roo::Excelx.new("/Users/untoldone/Downloads/UDS-2019-Full-Dataset.xlsx")
sheet1 = xlsx.sheet("HealthCenterSiteInfo")
sheet2 = xlsx.sheet("HealthCenterInfo")

puts sheet1.row(1)

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.xlsx

Issue

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

@wleeper
Copy link

wleeper commented Nov 11, 2020

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.

@anton-kachan-dev
Copy link

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants