再导入解析xls文件时,有的文件解析的总条数解析正确,有的多了一条解析代码 public List<HashMap<String, Object>> excuteExcel(InputStream is,
int sheetNumber) throws Exception {

HSSFWorkbook workbook = new HSSFWorkbook(is);

List<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();

//得到 sheet
HSSFSheet sheet = workbook.getSheetAt(sheetNumber);
// 一共有 sheet 
int rowCount = sheet.getLastRowNum(); if (rowCount < 1) {
return result;
}
//得到一个有多少个例
int cellCount = sheet.getRow(0).getLastCellNum();
// 遍历所有的row
for (int rowIndex = 0; rowIndex <= rowCount; rowIndex++) {
//得到俱体的
HSSFRow row = sheet.getRow(rowIndex);
if (null != row) {
HashMap<String, Object> rowData = new HashMap<String, Object>();

// 遍历例cell
for (short cellIndex = 0; cellIndex < cellCount; cellIndex++) {
HSSFCell cell = row.getCell(cellIndex);
// 得到例的值
Object cellStr = this.getCellString(cell)==null?"":this.getCellString(cell);
                                     String str=cellStr.toString();
                                     if(str!=null){
                               str=str.replaceAll("'", "");
                                      }
rowData.put(String.valueOf(cellIndex), cellStr);
 
}
result.add(rowData);
}
}
return result;
}

解决方案 »

  1.   

    哦 你的意思是判断最后一条是否为空,为空就remove掉嘛
      

  2.   

    这个验证下打出的内容,验证的时候前面加个标志。看看到底多的是什么。这个要看你的要求,如果需要就不做操作,如果不需要就remove掉呗。个人觉得应该默认都要去掉null的数据吧。就像你说的if()...else...
      

  3.   


    WARN - com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(629) | com.mchange.v2.resourcepool.BasicResourcePool@da6d09 -- an attempt to checkout a resource was interrupted, and the pool is still live: some other thread must have either interrupted the Thread attempting checkout!
    java.lang.InterruptedExceptionWARN - com.mchange.v2.lang.VersionUtils.<clinit>(56) | java.version ''1.6.0_10-rc2'' could not be parsed. Defaulting to JDK 1.1.
    java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException[code=Java]java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException
    [Cause: java.lang.InterruptedException[/code]