Skip to content

Instantly share code, notes, and snippets.

@springaki
Last active December 19, 2015 09:19
Show Gist options
  • Save springaki/5932204 to your computer and use it in GitHub Desktop.
Save springaki/5932204 to your computer and use it in GitHub Desktop.
POI のA1形式での範囲指定と矩形4点の取り方
{
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