-
Notifications
You must be signed in to change notification settings - Fork 256
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
Convenience method for accessing individual merged cells, rather than just a reference #381
Comments
Here's a more elaborate version. module RubyXL
module CellConvenienceMethods
def borders
merged_cells.flat_map { |cell|
[:top, :left, :right, :bottom].filter_map { |direction|
direction if cell.get_border(direction)
}
}.uniq
end
def merged_cells
worksheet.merged_cells.each { |mcell|
row_range, col_range = mcell.ref.row_range, mcell.ref.col_range
if row_range.begin == self.row && col_range.begin == self.column
return row_range.flat_map { |r| col_range.map { |c| worksheet[r][c] } }
end
} if worksheet.merged_cells
[self]
end
end
end |
Bumping this, I would definitely find it useful in one of my scripts. |
@harsh183 Please propose the consumer facing API. |
Something like sheet = parsed_file[0]
sheet.merged_cell_at([5, 3])
sheet.merged_cell_at(RubyXL::Reference.ref2ind('A1')) # why I'm thinking of array input Possibly having merged cells also support |
@harsh183 So you are saying that for given (X,Y) you want to know the (X1....X2, Y1.....Y2) of the merged cell, of which the cell (X,Y) is a part of? |
Yeah that works, and being able to get/set properties of the entire merged cell. |
Some properties are not set at the global merged cell level, but at the level of the individual cells which are merged. Borders are one example. The API should allow support for that. |
@caramdache precisely, so use your chance, go ahead and propose an API! |
@caramdache do you mean something like And the rest can have a merged cell level set for things that can be like content? For my project I'm just looking for merged_cell_at(x,y) but this is a part of the gem that can really be expanded on in interesting directions I feel. |
@harsh183 I meant an iterator that provides the individual cells that are part of a merge range. @weshatheleopard my use case was to be able to obtain the borders of a group of merged cells. The borders are defined for each individual cell, hence the need for an iterator to obtain these cells. |
Yeah, I think that'll be generally useful for a lot of things. |
Merged cells are a little bit of a red herring. Sometimes you want to access the actual cells rather than the reference/the MergedCell's. For example to obtain indivual borders for each of the cells in the merge. Which is required to be able to obtain the exact borders.
In doing this work, I have found the following method useful. It may be a desirable inclusion in the library, probably under a more sophisticated form.
The text was updated successfully, but these errors were encountered: