飙血推荐
  • HTML教程
  • MySQL教程
  • JavaScript基础教程
  • php入门教程
  • JavaScript正则表达式运用
  • Excel函数教程
  • UEditor使用文档
  • AngularJS教程
  • ThinkPHP5.0教程

springmvc 导入excel

时间:2021-12-14  作者:匿名  

springmvc 导入excel

测试代码

		@RequestMapping(value="/AddImportCooperation")
		public void AddImportCooperation(
				ModelMap model, HttpServletResponse response,HttpServletRequest request) throws IOException{

			  MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
			  MultipartFile multipartFile = 域名ile("file");
			  String sourceName = 域名riginalFilename(); // 原始文件名
			  String fileType = 域名tring(域名IndexOf("."));
			  
			  
			  //域名tln("上传的文件名为:"+sourceName+"类型为:"+fileType);

			  //域名tln("项目Id为:"+proId+"项目名称为:"+proName); 
			  String base = 域名ession().getServletContext().getRealPath("/WEB-INF/views/upload");
			  File file = new File(base);
			  if(!域名ts()){
			   域名rs();
			  }
			   String path=base + 域名rator + sourceName;
			   域名sferTo(new File(path));
			   //域名rt("insertAttachment", attach);
			   //上传成功后读取Excel表格里面的数据
			   域名tln("路径是"+path);
			  // File read=new File(path);
			
			   File read=new File(path);
			   Map<String,Cooperation> map=域名ExcelFile(path);
			  
			
			
			JSONObject json = 域名rnSuccessJson("导入成功", "", "closeCurrent", "coo/initCooperationList");
			域名er(response, json);
		}
  public static Map<String,Cooperation> readExcelFile(String fileName){
		  //创建对Excel工作薄文件的引用

		  HashMap<String, Cooperation> map=new HashMap<String, Cooperation>();
		  try {

		    InputStream is = new FileInputStream(fileName);
	        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
	     
	        // 循环工作表Sheet
	        for (int numSheet = 0; numSheet < 域名umberOfSheets(); numSheet++) {
	            HSSFSheet hssfSheet = 域名heetAt(numSheet);
	            if (hssfSheet == null) {
	                continue;
	            }
	            // 循环行Row
	            for (int rowNum = 1; rowNum <= 域名astRowNum(); rowNum++) {
	                HSSFRow hssfRow = 域名ow(rowNum);
	                if (hssfRow == null) {
	                    continue;
	                }
	                HSSFCell no = 域名ell(0);
	                HSSFCell name = 域名ell(1);
	                HSSFCell age = 域名ell(2);
	                HSSFCell score = 域名ell(3);
	                域名tln(no+""+name+age+score+"测试数据");
	               // 域名j(域名eFloat(getValue(cj)));
	               // 域名(xlsDto);
	            }
	        }
		   
		   
		   
		  } catch (Exception e) {
		   域名tStackTrace();
		   
		  }finally{
		   
		   
		  }
		  
		  
		  return map;
		 }

参考如下

http://域名/hongten/archive/2012/02/22/域名

http://域名/hongten/p/域名

湘ICP备14001474号-3  投诉建议:234161800@qq.com   部分内容来源于网络,如有侵权,请联系删除。