蔡德晨 5 years atrás
parent
commit
c2d6278f15
1 changed files with 39 additions and 0 deletions
  1. 39 0
      src/main/java/com/jeeplus/common/utils/excel/ImportExcel.java

+ 39 - 0
src/main/java/com/jeeplus/common/utils/excel/ImportExcel.java

@@ -226,6 +226,45 @@ public class ImportExcel {
 		}
 		return val;
 	}
+
+	public Object getValue(int rowNum,int column){
+		Row row = this.sheet.getRow(rowNum);
+		Object val = "";
+		try {
+			Cell cell = row.getCell(column);
+			if (cell != null) {
+				if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
+					// val = cell.getNumericCellValue();
+					// 当excel 中的数据为数值或日期是需要特殊处理
+					if (HSSFDateUtil.isCellDateFormatted(cell)) {
+						double d = cell.getNumericCellValue();
+						Date date = HSSFDateUtil.getJavaDate(d);
+						SimpleDateFormat dformat = new SimpleDateFormat(
+								"yyyy-MM-dd");
+						val = dformat.format(date);
+					} else {
+						NumberFormat nf = NumberFormat.getInstance();
+						nf.setGroupingUsed(false);// true时的格式:1,234,567,890
+						val = nf.format(cell.getNumericCellValue());// 数值类型的数据为double,所以需要转换一下
+					}
+				} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
+					val = cell.getStringCellValue();
+				} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
+					val = cell.getCellFormula();
+				} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
+					val = cell.getBooleanCellValue();
+				} else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
+					val = cell.getErrorCellValue();
+				}
+			} else {
+				val = "0";
+			}
+		} catch (Exception e) {
+			return val;
+		}
+		return val;
+
+	}
 	
 	/**
 	 * 获取导入数据列表