freemarker word

        Map<String, Object> map = new HashMap<String, Object>();
        Projset projset = projsetService.findById(id);
        String sql = "select * from urm_user where id=" + "'" + projset.getManager() + "'";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        map.put("manager", list.get(0).get("FULLNAME"));
        map.put("projsetname", projset.getPname());
        map.put("cnum", projset.getCnum());
        createWord(map, "entryprogressword.ftl "," D: / wordFile / "," project manager appointment .doc ");
/ ** 
     * Generate word file 
     * @param dynamic data dataMap word needs to show, with a map collection to save 
     * @param templateName word template name, for example: test.ftl 
     * @param filePath file generated by the target path, for example: D : / WordFile / 
     * @param fileName generated file name, for example: Test.doc 
     * @throws IOException 
      * / 
    @SuppressWarnings ( "an unchecked" )
     public  void createWord (Datamap the Map, templateName String, String filePath, String fileName) {
         the try {
             // create a configuration example of 
            the configuration the configuration = new newThe Configuration ();
             // set the encoding 
            configuration.setDefaultEncoding ( "UTF-8" );
             // FTL unified template file to put com.lun.template package below 
            configuration.setClassForTemplateLoading ( the this .getClass (), "../ Template" );
             // get the template 
            template template = configuration.getTemplate (templateName);
             // output files 
            file the outFile = new new file (filePath + File.separator + fileName);
             // if the output target folder does not exist, create 
            IF ! ( the outFile .getParentFile (). exists ()) {
                outFile.getParentFile () mkdirs ();. 
            } 
            // the template file and the data model to generate combined 
            Writer OUT = new new BufferedWriter, ( new new the OutputStreamWriter ( new new a FileOutputStream (the outFile), "UTF-. 8" ));
             // build file 
            template. Process (Datamap, OUT);
             // Close stream 
            out.flush (); 
            the out.close (); 
            } the catch (Exception E) { 
                e.printStackTrace (); 
            } 
        }

 

Guess you like

Origin www.cnblogs.com/cmz-32000/p/12340046.html