导出文件
作者:互联网
目录
html导出doc
注意点
- 如果导出html标签没有被解析,那就创建一个空的标准html文件,把自己的内容包在里面。
controller
点击查看代码
/**
* 导出word
* @param id
* @param request
* @param response
* @throws Exception
*/
@RequestMapping("/exportWord")
@ResponseBody
public void exportWord(@RequestParam String id,HttpServletRequest request, HttpServletResponse response) throws Exception {
FaultRecord bean = faultRecordService.findById(FaultRecord.class, id);
Map<String, Object> map = new HashMap<String, Object>();
String filePath = ExcelUtil.getTempletFilePath(request, "Doc1.doc");
// String value = "<html>";
String value = "<html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title>Title</title>\n</head>\n<body>\n";
value += Optional.ofNullable(bean).map(i -> i.getDisposal()).orElse("");
value += "</body>\n</html>";
map.put("disposal", value);
String URL = filePath;
File file = new File(URL);
PrintWriter out = null;
try {
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
response.setHeader("Content-disposition", "attachment; filename=03doc.doc");
out = response.getWriter();
out.println(value);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (out != null) {
out.flush();
out.close();
}
}
}
标签:文件,String,doc,导出,value,html,response,out 来源: https://www.cnblogs.com/jf666/p/16698491.html