-
-
Save springaki/5932204 to your computer and use it in GitHub Desktop.
POI のA1形式での範囲指定と矩形4点の取り方
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
String range = "A1:C5" | |
CellRangeAddress address = CellRangeAddress.valueOf(range); | |
int firstRow = address.getFirstRow(); | |
int lastRow = address.getLastRow(); | |
int firstColumn = address.getFirstColumn(); | |
int lastColumn = address.getLastColumn(); | |
} | |
////////// | |
{ | |
String rangesStr = "A1:C5,D6:F10"; | |
List<String> ranges = Arrays.asList(rangesStr.split(",")); | |
for (String range : ranges) { | |
CellRangeAddress address = CellRangeAddress.valueOf(range); | |
int firstRow = address.getFirstRow(); | |
int lastRow = address.getLastRow(); | |
int firstColumn = address.getFirstColumn(); | |
int lastColumn = address.getLastColumn(); | |
for (int rowIndex = firstRow; rowIndex <= lastRow; rowIndex++) { | |
Row row = sheet.getRow(rowIndex); | |
if (row == null) {continue;} | |
for (int colIndex = firstColumn; colIndex <= lastColumn ; colIndex++) { | |
Cell cell = row.getCell(colIndex); | |
if (cell == null) { continue; } | |
// 何か処理 | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment