Skip to content

Convenience method for accessing individual merged cells, rather than just a reference #381

@caramdache

Description

@caramdache

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.

def merged_cells(cell)
    return nil unless cell.worksheet.merged_cells
    
    cell.worksheet.merged_cells.each { |mcell|
        if mcell.ref.first_row == cell.row && mcell.ref.first_col == cell.column
            return mcell.ref.row_range.collect { |row|
                       mcell.ref.col_range.collect { |col|
                           cell.worksheet[row][col]
                       }
                   }
        end
    }
    
    nil
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions