1.导入
前端js和跳转页面
<t:dgToolBar title="导入单一模板" icon="icon-put" funname="Importonlyone"></t:dgToolBar>
function Importonlyone(title,url,gname) { gridname=gname; var ids = []; var rows = $("#"+gname).datagrid('getSelections'); if(rows.length==1){ openuploadwin('Excel导入', 'decMainController.do?upload&num=1&ids='+rows[0].id, "decMainList"); } }
<t:formvalid formid="formobj" layout="div" dialog="true" beforeSubmit="upload"> <fieldset class="step"> <div class="form"><t:upload name="fiels" buttonText="选择要导入的文件" uploader="${controller_name}.do?${empty method_name?'importExcel':method_name }" extend="*.xls;*.xlsx" id="file_upload" formData="documentTitle"></t:upload></div> <div class="form" id="filediv" style="height: 50px"></div> </fieldset> </t:formvalid>
后台跳转方法及导入解析
@RequestMapping(params = "upload") public ModelAndView upload(HttpServletRequest req) { req.setAttribute("controller_name","decMainController"); req.setAttribute("method_name","importonlyone"); req.setAttribute("ids", req.getParameter("ids")); return new ModelAndView("com/jeecg/decmain/pub_excel_upload"); }
@SuppressWarnings("unchecked") @RequestMapping(params = "importonlyone", method = RequestMethod.POST) @ResponseBody public AjaxJson importonlyone(HttpServletRequest request, HttpServletResponse response) throws Exception { AjaxJson j = new AjaxJson(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; List<MultipartFile> contactFile= new ArrayList<MultipartFile>(); Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { MultipartFile file = entity.getValue();// 获取上传文件对象 contactFile.add(file); } XSSFWorkbook wb;//2007以前的是HSSFWorkbook // 页 XSSFSheet sheet;//成品表 // 行 XSSFRow row;//成品表行 // 打开文件 try { wb = new XSSFWorkbook(contactFile.get(0).getInputStream()); } catch (IOException e) { e.printStackTrace(); wb = new XSSFWorkbook(); } sheet = wb.getSheetAt(0); int rowNum = sheet.getLastRowNum(); DecMainPage decMainPage=new DecMainPage(); row=sheet.getRow(1); String ieflag=getCellFormatValue(row.getCell(1));//进出口标识
}