本文实例为大家分享了springMVC导出word模板的具体代码,供大家参考,具体内容如下
controller 调用
@RequestMapping(value = "/exportWord")
public void exportWord(HttpServletResponse response, HttpServletRequest request) throws IOException {
String templatePath = request.getServletContext().getRealPath("") + "/template/税源信息比对.docx";
String fileName = new String("税源信息比对".getBytes("gb2312"), "ISO8859-1") + ".docx";
/*数据*/
Map params = new HashMap();
params.put("${name}", "aaaa");
params.put("${sex}", "bbbb");
TempleWordUtil wordUtil = new TempleWordUtil();
XWPFDocument doc;
InputStream is = new FileInputStream(templatePath);
// is = getClass().getClassLoader().getResourceAsStream(templatePath);
doc = new XWPFDocument(i