加以下两句就行了:
response.contentType = "application/vnd.ms-excel"
response.addheader "Content-Disposition", "attachment; filename=文件名.xls"
完整代码:
- <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
- <%
- response.contentType = "application/vnd.ms-excel"
- response.addheader "Content-Disposition", "attachment; filename=测试.xls"
- '下面只要会写table的HTML代码就行了
- %>
- <table width="800" border="1">
- <tr align="center">
- <td colspan="3">测试</td>
- </tr>
- <tr>
- <td align="center">测试</td>
- <td align="center">测试</td>
- <td align="center">测试</td>
- </tr>
- <tr>
- <td align="center">测试1</td>
- <td align="center">测试1</td>
- <td align="center">测试1</td>
- </tr>
- </table>
上面的,还可以设置table的border,以及背景色等等,这些都可以反映到Excel文件,但是不要用css来设置。