/** * Return the cell, taking account of merged regions. Allows you to find the * cell who's contents are Shown in a given position in the sheet. * * <p>If the cell at the given co-ordinates is a merged cell, this will * return the primary (top-left) most cell of the merged region.</p> * <p>If the cell at the given co-ordinates is not in a merged region, * then will return the cell itself.</p> * <p>If there is no cell defined at the given co-ordinates, will return * null.</p> */ public static ICell GetCellWithMerges(ISheet sheet, int rowIx, int colIx) { IRow r = sheet.GetRow(rowIx); if (r != null) { ICell c = r.GetCell(colIx); if (c != null) { // Normal, non-merged cell return(c); } } for (int mr = 0; mr < sheet.NumMergedRegions; mr++) { CellRangeAddress mergedRegion = sheet.GetMergedRegion(mr); if (mergedRegion.IsInRange(rowIx, colIx)) { // The cell wanted is in this merged range // Return the primary (top-left) cell for the range r = sheet.GetRow(mergedRegion.FirstRow); if (r != null) { return(r.GetCell(mergedRegion.FirstColumn)); } } } // If we Get here, then the cell isn't defined, and doesn't // live within any merged regions return(null); }
public static bool ContainsCell(CellRangeAddress cr, int rowIx, int colIx) { return(cr.IsInRange(rowIx, colIx)); }