java导出Excel

public void export() throws IOException{
HSSFWorkbook wb =*********  //生成的Excel
// 将文件存到浏览器设置的下载位置
String filename = "excel"+ ".xls";
response.setContentType("application/ms-excel;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename="
.concat(String.valueOf(URLEncoder.encode(filename, "UTF-8"))));
OutputStream out = response.getOutputStream();
try {
wb.write(out);// 将数据写出去
String str = "导出" + filename + "成功!";
System.out.println(str);
} catch (Exception e) {
e.printStackTrace();
String str1 = "导出" + filename + "失败!";
System.out.println(str1);
} finally {
out.close();
}
}

原文地址:https://www.cnblogs.com/cai170221/p/9417654.html