zdavatz / spreadsheet

The Ruby Spreadsheet by ywesee GmbH
http://spreadsheet.ch
GNU General Public License v3.0
1.13k stars 240 forks source link

Feature - Retrieve a cell by its name, not just row and column #177

Closed ardavis closed 8 years ago

ardavis commented 8 years ago

Is there a way to retrieve the contents of a cell by it's name, instead of just the row/col? This would make future changes to the spreadsheet easier for my application.

Reference: Stack Overflow Question

If it doesn't currently exist, is there a relatively simple way to patch the gem to accommodate?

zdavatz commented 8 years ago

What good would this feature do? Also, spreadsheet gem does NOT parse XLSX files. For that you need to use https://github.com/weshatheleopard/rubyXL gem.

ardavis commented 8 years ago

That's okay. We are currently parsing .xls files, they are fairly old templates. Basically by allowing the ability to find a cell by it's name, it can let the template designers modify the template however they see fit. If they feel a cell needs to be moved, then they can move it and it won't affect our ability to ingest the file.

Secondly, new columns often get added to the templates that we ingest. Here is some pseudo code of how we ingest it:

# Column locations
NAME = 4
ADDRESS = 5
PHONE = 6

....

rows.each do |row|
    self.name = row[NAME]
    self.address = row[ADDRESS]
    self.phone = row[PHONE]
end

Unfortunately if the template gets changed, and FAVORITE_COLOR were to be added right after name, now we have to modify the column locations for all cells after it.

We have about 80 columns, so when things get added, it's a massive pain to change all of those numbers. If we could instead retrieve NAME_HEADER or something, then we could figure out what column it's in, regardless of where it is in the Excel file.

zdavatz commented 8 years ago

Ok, we will think about this but I do not think this will be easy.

ardavis commented 8 years ago

That's understandable. I wasn't sure, that's why I figured I'd ask. Thanks for even considering.

zdavatz commented 8 years ago

I will close this, but that does not mean the feature will not be implemented.