The third project to be speaking with jeecg (Custom Import Export)

1. Import

The front page and jump js

 < T: dgToolBar title = "single template Import" 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>

Import and analytical background jump method

     @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, a MultipartFile> filemap = multipartRequest.getFileMap ();
                     for (of Map.Entry <String, a MultipartFile> Entity: fileMap.entrySet ()) { 
                        a MultipartFile File = entity.getValue (); // Get upload file object 
                       contactFile.add (file); 
                  } 
                    XSSFWorkbook wb; // 2007 is the previous HSSFWorkbook 
                    // page 
                    XSSFSheet sheet; // finished form
                     // line 
                    XSSFRow row; // finished table row
                     // open the file 
                    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 ieflaggetCellFormatValue = (row.getCell (. 1)); // Importers identifier 
          }

 

Guess you like

Origin www.cnblogs.com/xujiating/p/12058632.html