当前位置 : 主页 > 编程语言 > java >

Excel的导入

来源:互联网 收集:自由互联 发布时间:2021-06-28
gistfile1.txt 文件导入,前台需要引入ajaxfileupload.js$.ajaxFileUpload({ url: 'importSubject', //用于文件上传的服务器端请求地址 type: 'post', secureuri: false, //是否需要安全协议,一般设置为false fileE
gistfile1.txt
文件导入,前台需要引入ajaxfileupload.js
$.ajaxFileUpload({
    url: 'importSubject', //用于文件上传的服务器端请求地址
    type: 'post',
    secureuri: false, //是否需要安全协议,一般设置为false
    fileElementId: $("input[name='uploadExcel']").attr("id"),//文件上传域的ID
    contentType : false,// 告诉jQuery不要去设置Content-Type请求头
    data:{
        sid:$("#sid").val(),
        billNum:$("#billnum").val(),
        batchId:batchId
    },
    dataType: 'json', //返回值类型 一般设置为json
    success: function (data, status){  //服务器成功响应处理函数
        $('#ftkm').datagrid('loadData',{total:0,rows:[]});
        $('#ftkm').datagrid({
            data:data
        });
        $('#ReportKM').window('close');
    },
    error: function (data, status, e){//服务器响应失败处理函数
        alert(e);
    }
});
后台java类接收
/**
    * 导入excel
    * @param request
    * @return
    * @throws Exception
    */
@RequestMapping(value = "/importSubject", method = RequestMethod.POST)
@ResponseBody
public Object reportSubject(HttpServletRequest request,
        @RequestParam(value = "uploadExcel", required = false) MultipartFile uploadExcel,
        @RequestParam String batchId,
        @RequestParam String billNum,
        HttpServletResponse response
        )  throws Exception{
    ModelAndView ret = new ModelAndView();
    InputStream in = null;
    try{        
        List
 
  > subjectList =null;
        Map
  
    paraMap = new HashMap<>(); //获取前台excel输入流 String filename = uploadExcel.getOriginalFilename(); in = uploadExcel.getInputStream(); subjectList = this.readXls(filename,in,batchId,billNum);//解析excel数据方法,代码不贴了 paraMap.put("subjects", subjectList); paraMap.put("billNum", billNum); paraMap.put("batchId", batchId); String result = this.restTemplte.postForEntity(URL + "/shareManage/importShareSubject", paraMap, String.class).getBody(); return result; }catch (Exception e) { e.printStackTrace(); ret.setViewName("errors/error"); ReturnJsonModel retJson = new ReturnJsonModel("error", "系统操作异常,错误:" + e.getMessage()); ret.addObject("msg", retJson); return ret; } }
  
 
网友评论