其他分享
首页 > 其他分享> > 导出文件

导出文件

作者:互联网

目录

html导出doc

注意点

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