zoukankan      html  css  js  c++  java
  • 获取合并单元格中值的一个方法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;
        }
  • 相关阅读:
    杂题
    jzoj5679
    CF434E
    jzoj6152
    jzoj6150
    mysql 第06章 运算符
    mysql 第05章 数据类型
    mysql 第04章 SQL语句
    mysql 第03章 体系结构
    mysql 第02章 基本操作
  • 原文地址:https://www.cnblogs.com/softidea/p/4249608.html
Copyright © 2011-2022 走看看