Skip to content

Commit 98a25ba

Browse files
committed
Added a method that returns the indexes of a cell passing the cell name as input
1 parent 8f5a111 commit 98a25ba

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/main/java/io/github/mbenincasa/javaexcelutils/tools/ExcelUtility.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,17 @@ public static String getCellName(int row, int col) {
4646
String colName = CellReference.convertNumToColString(col);
4747
return colName + (row + 1);
4848
}
49+
50+
/**
51+
* Return an array containing column and row indexes
52+
* @param cellName cell name
53+
* @return an array containing column and row indexes
54+
* @since 0.4.2
55+
*/
56+
public static int[] getCellIndexes(String cellName) {
57+
CellReference cellRef = new CellReference(cellName);
58+
int row = cellRef.getRow();
59+
int col = cellRef.getCol();
60+
return new int[]{row, col};
61+
}
4962
}

src/test/java/io/github/mbenincasa/javaexcelutils/tools/ExcelUtilityTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ void getCellName() {
3232
String cellName = ExcelUtility.getCellName(row, col);
3333
Assertions.assertEquals("A1", cellName);
3434
}
35+
36+
@Test
37+
void getCellIndexes() {
38+
int[] indexes = ExcelUtility.getCellIndexes("A2");
39+
Assertions.assertEquals(2, indexes.length);
40+
Assertions.assertEquals(1, indexes[0]);
41+
Assertions.assertEquals(0, indexes[1]);
42+
}
3543
}

0 commit comments

Comments
 (0)