问题描述
导入方法:privateList<BOZJProjectTobeBuiltImportBean>convertBeansFromExcelForProject(HttpServletRequestrequest,HashMap<String,String>msg,StringBufferfileName,StringBufferbactchno,StringregionId,StringPROJECT_KIND)throwsException{List<BOZJProjectTobeBuiltImportBean>beanList=newArrayList<BOZJProjectTobeBuiltImportBean>();Object[]objs=ApacheUploadTool.getUploadFileInfo(request);List<Object>fileList=(List<Object>)objs[0];java.text.DateFormatDateFormat=newjava.text.SimpleDateFormat("yyyyMMddHHmmss");bactchno.append(DateFormat.format(ZJRMFactory.getIImportAddrSV().getDBSysdate())+(String)msg.get(districtindex));IDistrictInfoobjDistSRV=(IDistrictInfo)ServiceFactory.getService(Constants.SERVICE_DISTRICTINFO);IDistrictValueaDistrict=objDistSRV.getDistrictById((String)msg.get(districtindex));districtName=aDistrict.getCityName();if(null==fileList||fileList.size()==0){thrownewException("没有文件可供导入");}FileItemfileItem=(FileItem)fileList.get(0);//fileName.append(fileItem.getFieldName());Stringname=fileItem.getName();fileName.append(name);//获取导入类型的长度BOZJProjectImportFileColRelBean[]colbean=ZJIomFactory.getIZJProjectManagementSV().getZJProjectImportFileColRel(PROJECT_KIND,"","");if(colbean.length==0||null==colbean){ExceptionUtil.throwDirectSFException("zj_project_import_file_col_rel中未对project_kind为"+PROJECT_KIND+"的类型做配置");}Workbookworkbook=Workbook.getWorkbook(fileItem.getInputStream());Sheetsheet=workbook.getSheet(0);introws=sheet.getRows();if(null==sheet||rows<=1){thrownewException("文件中没有数据");}if(rows>limitCols+1){rows=limitCols+1;thrownewException("超过最大限制行数"+":"+limitCols);}Cell[]titles=sheet.getRow(0);if((titles.length)!=colbean.length){thrownewException("文件格式错误,请检查文件列是否符合格式!");}//开始解读从第二行开始解析beanBOZJProjectTobeBuiltImportBeanbean=null;StringcolName=null;for(inti=1;i<rows;i++){Cell[]cells=sheet.getRow(i);bean=newBOZJProjectTobeBuiltImportBean();//bean.setRegionId(regionId);/////------->这里可能需要修改//行号//bean.setExt5((i+1)+"");//从第一列开始取数据for(intj=0;j<Math.min(colbean.length,cells.length);j++){bean.set(colbean[j].getColCode(),cellContentValue(cells,j));}beanList.add(bean);}workbook.close();returnbeanList;}文件中某个字段后面有空格符,导入后查表情况like能查出结果,等于的时候查不出,我看值后面是没有空格的。如果要在导入的时候把字段前后空格去掉要如何处理,
解决方案
解决方案二:
"".trim()可以去掉字符串的前后空格
解决方案三:
你看你的cellContentValue如何获取值的;使用JAVA字符串的trim来去空格就可以了呀。
解决方案四:
在参数传递的时候,trim掉空格。然后再检索。
解决方案五:
trim()去空格看看