/** * * 功能描述: <br> * 〈功能详细描述〉输出excle * * @param titles 标题 * @param contents 内容 * @param fileName 文件名 * @param response */ protected void createExcle(List<Object> titles, List<List<Object>> contents, String fileName, HttpServletResponse response) { response.setContentType("application/msword;charset=UTF-8"); response.setHeader("Content-disposition", "attachment;filename=" + fileName); response.addHeader("Pragma", "no-cache"); response.addHeader("Cache-Control", "no-cache"); response.addDateHeader("Expries", 0); ExcelWriter excelWriter = null; OutputStream os = null; try { excelWriter = new ExcelWriter(null, ExcelType.XLSX); excelWriter.createSheet("sheet"); excelWriter.addRow("sheet", 1, titles);// 标题 for (int i = 0; i < contents.size(); i++) {// 内容 excelWriter.addRow("sheet", i + 2, contents.get(i)); } os = response.getOutputStream(); excelWriter.flush(os); } catch (IOException e) { } finally { if (os != null) { try { os.close(); } catch (IOException e) { } } } }