代码:
util类
if(workbook !=null){
OutputStream out=null;
try
{
String fileName = "Excel-" + String.valueOf(System.currentTimeMillis()).substring(4, 13) + ".xls";
String headStr = "attachment; filename=\"" + fileName + "\"";
//
//response.reset();
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", headStr);
out = response.getOutputStream();
System.out.println("fileName:"+fileName);
System.out.println("开始写文件#####################");
workbook.write(out);
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
finally {
out.close();
}
controller:
ExportExcel ex = new ExportExcel(title, rowsName, dataList);
HttpServletResponse response=Mvcs.getResp();
ex.export(response);
System.out.println();