package com.qxueyou.scc.base.util; import java.io.IOException; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateExceptionHandler; public final class WordExportUtils { public Configuration configure; public WordExportUtils(){ configure = new Configuration(Configuration.VERSION_2_3_21); configure.setDefaultEncoding("utf-8"); } /** * ¸ù¾ÝDocÄ£°åÉú³ÉwordÎļþ * @param dataMap ÐèÒªÌîÈëÄ£°åµÄÊý¾Ý * @param downloadType ÎļþÃû³Æ */ public Template createDoc(String downloadType){ try { //ÉèÖÃÄ£°å×°Ö÷½·¨ºÍ·¾¶£¬FreeMarkerÖ§³Ö¶àÖÖÄ£°å×°ÔØ·½·¨¡£¿ÉÒÔÖØservlet£¬classpath,Êý¾Ý¿â×°ÔØ¡£ //¼ÓÔØÄ£°åÎļþ£¬·ÅÔÚtestDocÏ configure.setClassForTemplateLoading(this.getClass(), ""); //ÉèÖÃÒì³£´¦ÀíÆ÷ configure.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER); return configure.getTemplate(downloadType);//¶¨ÒåTemplate¶ÔÏó£¬×¢ÒâÄ£°åÀàÐÍÃû×ÖÓëdownloadTypeÒªÒ»Ö } catch (IOException e) { e.printStackTrace(); } return null; } }