diff --git a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java index 45700dd74..334e9f4ea 100644 --- a/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java +++ b/src/main/java/com/zhgd/xmgl/util/ExcelUtils.java @@ -362,4 +362,39 @@ public class ExcelUtils { } }*/ + /** + * 获取单元格内容,包括合并单元格的 + * + * @param sheet sheet表单 + * @param row 当前行下标 + * @param col 当前列下标 + * @return + */ + public static String getSheelValue(Sheet sheet, int row, int col) { + int mergedRegions = sheet.getNumMergedRegions(); + for (int i = 0; i < mergedRegions; i++) { + CellRangeAddress region = sheet.getMergedRegion(i); + //行开始下标 + int firstRow = region.getFirstRow(); + //行结束下标 + int lastRow = region.getLastRow(); + //列开始下标 + int firstColumn = region.getFirstColumn(); + //列结束下标 + int lastColumn = region.getLastColumn(); + if (row >= firstRow && row <= lastRow) { + if (col >= firstColumn && col <= lastColumn) { + Row fRow = sheet.getRow(firstRow); + Cell cell = fRow.getCell(firstColumn); + //所有内容已字符串形式处理 + cell.setCellType(CellType.STRING); + return cell.getStringCellValue(); + } + } + } + Cell cell = sheet.getRow(row).getCell(col); + //所有内容已字符串形式处理 + cell.setCellType(CellType.STRING); + return cell.getStringCellValue(); + } }