导入人员考勤excel

This commit is contained in:
guoshengxiong 2024-09-10 17:23:19 +08:00
parent c2196131ce
commit b332e61548

View File

@ -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();
}
} }