jxls导出EXCEL模板

http://jxls.sourceforge.net/

    InputStream templateInput = null;
    InputStream in = null;
    OutputStream out = null;
    try {
        templateInput = request.getSession().getServletContext().getResourceAsStream("/downloads/project/fpfa.xls");
        XLSTransformer transformer = new XLSTransformer();
        Map<String, Object> beans = new HashMap<String, Object>();
        Workbook workbook = transformer.transformXLS(templateInput, beans);

        // 下载文件
        File _tempfile = IOUtil.createTempFile();
        out = new FileOutputStream(_tempfile);
        workbook.write(out);
        in = new FileInputStream(_tempfile);
        HttpUtils.download(response, excelname + ".xls", in);
        out.flush();
    } finally {
        if (templateInput != null) {
            templateInput.close();
        }
        if (in != null) {
            in.close();
        }
        if (out != null) {
            out.close();
        }
    }

公司项目里的代码,个别部分自行YY

原文地址:https://www.cnblogs.com/duelsol/p/3760543.html