int t = sheet.getFirstRowNum();
int b = sheet.getLastRowNum();
//top row
int minr = -1;
for(int r = t; r <= b && minr < 0; ++r) {
final Row rowobj = sheet.getRow(r);
if (rowobj != null) {
int ll = rowobj.getFirstCellNum();
if (ll < 0) { //empty row
continue;
}
int rr = rowobj.getLastCellNum() - 1;
for(int c = ll; c <= rr; ++c) {
final Cell cell = rowobj.getCell(c);
if (!BookHelper.isBlankCell(cell)) { //first no blank row
minr = r;
break;
}
}
}
}
//bottom row
int maxr = -1;
for(int r = b; r >= minr && maxr < 0; --r) {
final Row rowobj = sheet.getRow(r);
if (rowobj != null) {
int ll = rowobj.getFirstCellNum();
if (ll < 0) { //empty row
continue;
}
int rr = rowobj.getLastCellNum() - 1;
for(int c = ll; c <= rr; ++c) {
final Cell cell = rowobj.getCell(c);
if (!BookHelper.isBlankCell(cell)) { //first no blank row
maxr = r;
break;
}
}
}
}
//left col
int minc = Integer.MAX_VALUE;
for(int r = minr; r <= maxr; ++r) {
final Row rowobj = sheet.getRow(r);
if (rowobj != null) {
int ll = rowobj.getFirstCellNum();
if (ll < 0) { //empty row
continue;
}
int rr = rowobj.getLastCellNum() - 1;
for(int c = ll; c < minc && c <= rr; ++c) {
final Cell cell = rowobj.getCell(c);
if (!BookHelper.isBlankCell(cell)) { //first no blank row
minc = c;
break;
}
}
}
}
//right col
int maxc = -1;
for(int r = minr; r <= maxr; ++r) {
final Row rowobj = sheet.getRow(r);
if (rowobj != null) {
int ll = rowobj.getFirstCellNum();
if (ll < 0) { //empty row
continue;
}
int rr = rowobj.getLastCellNum() - 1;
for(int c = rr; c > maxc && c >= ll; --c) {
final Cell cell = rowobj.getCell(c);
if (!BookHelper.isBlankCell(cell)) { //first no blank row
maxc = c;
break;
}
}