获取合并单元格中值的一个方法POI

获取合并单元格中值的一个方法POI

    private static String getCellValueForMerginRegion(Cell cell) {

        int rowIdx=cell.getRowIndex();
Sheet sheet=cell.getSheet();
int mergedRegions=sheet.getNumMergedRegions();
for (int i = 0; i < mergedRegions; i++) {
CellRangeAddress cellRangeAddress=sheet.getMergedRegion(i); if (cellRangeAddress.getLastColumn()==0) {
int firstRowIdx=cellRangeAddress.getFirstRow();
int lastRowIdx=cellRangeAddress.getLastRow();
if (rowIdx<=lastRowIdx&&rowIdx>=firstRowIdx) {
String cellValue = null;
for (int j = firstRowIdx; j <=lastRowIdx; j++) {
cellValue=getCellValue(sheet.getRow(j).getCell(0));
if (cellValue.trim().length()==0) {
System.out.println("firstRowIdx:"+firstRowIdx+",lastRowIdx:"+lastRowIdx+":"+cellValue);
continue;
}
break;
} return cellValue;
}
} } return null;
}
上一篇:java后台调用http请求


下一篇:md5签名加密(用于java 后台调用短信平台接口实现发短信)