diff --git a/src/java/org/apache/poi/ss/util/SheetUtil.java b/src/java/org/apache/poi/ss/util/SheetUtil.java index 71c3c3cb4..6b55e223f 100644 --- a/src/java/org/apache/poi/ss/util/SheetUtil.java +++ b/src/java/org/apache/poi/ss/util/SheetUtil.java @@ -293,4 +293,41 @@ public class SheetUtil { return false; } + /** + * 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. + * + *
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. + *
If the cell at the given co-ordinates is not in a merged region, + * then will return the cell itself. + *
If there is no cell defined at the given co-ordinates, will return
+ * null.
+ */
+ public static Cell getCellWithMerges(Sheet sheet, int rowIx, int colIx) {
+ Row r = sheet.getRow(rowIx);
+ if (r != null) {
+ Cell c = r.getCell(colIx);
+ if (c != null) {
+ // Normal, non-merged cell
+ return c;
+ }
+ }
+
+ for (int mr=0; mr