|
@@ -367,47 +367,49 @@ public class FilesUtil {
|
|
|
|
|
|
for(int i=firstrow; i<rownum; i++){
|
|
|
Row row = sheet.getRow(i);
|
|
|
- Map<String,Object> map = new HashMap<String,Object>();
|
|
|
- for(int j=0; j<titleKey.length; j++){
|
|
|
- System.out.println(i+":"+j);
|
|
|
- Cell cell = row.getCell(j);
|
|
|
- String cellValue="";
|
|
|
- if(cell != null){
|
|
|
- switch (cell.getCellType()){
|
|
|
- case NUMERIC: // 数字
|
|
|
- if(HSSFDateUtil.isCellDateFormatted(cell)){
|
|
|
- //用于转化为日期格式
|
|
|
- Date d = cell.getDateCellValue();
|
|
|
- DateFormat formater = new SimpleDateFormat("yyyyMMdd");
|
|
|
- cellValue = formater.format(d);
|
|
|
- }else{
|
|
|
- // 用于格式化数字,只保留数字的整数部分
|
|
|
- cellValue = df.format(cell.getNumericCellValue()); //cell.getNumericCellValue() + "";
|
|
|
- }
|
|
|
- break;
|
|
|
- case STRING: // 字符串
|
|
|
- cellValue = cell.getStringCellValue();
|
|
|
- break;
|
|
|
- case BOOLEAN: // Boolean
|
|
|
- cellValue = cell.getBooleanCellValue() + "";
|
|
|
- break;
|
|
|
- case FORMULA: // 公式
|
|
|
- cellValue = cell.getCellFormula() + "";
|
|
|
- break;
|
|
|
- case BLANK: // 空值
|
|
|
- cellValue = "";
|
|
|
- break;
|
|
|
- case ERROR: // 故障
|
|
|
- cellValue = "非法字符";
|
|
|
- break;
|
|
|
- default:
|
|
|
- cellValue = "未知类型";
|
|
|
- break;
|
|
|
- }
|
|
|
+ if(row != null) {
|
|
|
+ Map<String,Object> map = new HashMap<String,Object>();
|
|
|
+ for(int j=0; j<titleKey.length; j++){
|
|
|
+ System.out.println(i+":"+j);
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ String cellValue="";
|
|
|
+ if(cell != null){
|
|
|
+ switch (cell.getCellType()){
|
|
|
+ case NUMERIC: // 数字
|
|
|
+ if(HSSFDateUtil.isCellDateFormatted(cell)){
|
|
|
+ //用于转化为日期格式
|
|
|
+ Date d = cell.getDateCellValue();
|
|
|
+ DateFormat formater = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ cellValue = formater.format(d);
|
|
|
+ }else{
|
|
|
+ // 用于格式化数字,只保留数字的整数部分
|
|
|
+ cellValue = df.format(cell.getNumericCellValue()); //cell.getNumericCellValue() + "";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case STRING: // 字符串
|
|
|
+ cellValue = cell.getStringCellValue();
|
|
|
+ break;
|
|
|
+ case BOOLEAN: // Boolean
|
|
|
+ cellValue = cell.getBooleanCellValue() + "";
|
|
|
+ break;
|
|
|
+ case FORMULA: // 公式
|
|
|
+ cellValue = cell.getCellFormula() + "";
|
|
|
+ break;
|
|
|
+ case BLANK: // 空值
|
|
|
+ cellValue = "";
|
|
|
+ break;
|
|
|
+ case ERROR: // 故障
|
|
|
+ cellValue = "非法字符";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ cellValue = "未知类型";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put(titleKey[j], cellValue);
|
|
|
}
|
|
|
- map.put(titleKey[j], cellValue);
|
|
|
+ list.add(map);
|
|
|
}
|
|
|
- list.add(map);
|
|
|
}
|
|
|
return list;
|
|
|
}
|