第一種也是比較好的方法:
String str=afwtHtml;
FileWriter writer; try { writer = new FileWriter("D:\logs\nihao2.xls"); writer.write(str); writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } return "ExportFinished";
第二種:
在後臺方法中加上前兩句,在瀏覽器就會以excel形式下載
response.setHeader("Content-Disposition","attachment;filename=aaa.xls"); response.setContentType("application/vnd.ms-excel"); String afwtHtml = "<table>...</table>" return afwtHtml;