ASP具备动态输出任一Office应用程序文件格式的功能在开始编写代码之前我们首先需要做的就是设置正确的文件类型因为浏览器需要知道如何处理文件第二步是编辑文件名称我们可以使用HTML和CSS来创建Word文档或Excel文档的样式
下面这段例子代码可用于在线创建Word文档
以下是引用片段
<%
ResponseContentType = application/msword
ResponseAddHeader ContentDisposition attachment;filename=NAMEdoc???
responseWrite(Dotnetindexcom : <a href=visit/>http://wwwdotnetindexcom>Visit Site</a><br> & vbnewline)
responseWrite(<h>We can use HTML codes for word documents</h>)
responseWrite (<div style=padding:px; font:px arial>CSS can be used tooo</span>)
%>
下面这段例子代码可用于在线创建Excel文档
以下是引用片段
BORDER
RIGHT: #cccccc
px solid; PADDING
RIGHT:
px; BORDER
TOP: #cccccc
px solid; PADDING
LEFT:
px; BACKGROUND: #f
f
f
; PADDING
BOTTOM:
px; MARGIN:
px
px; BORDER
LEFT: #cccccc
px solid; PADDING
TOP:
px; BORDER
BOTTOM: #cccccc
px solid
><%
ResponseAddHeader ContentDisposition attachment;filename=membersxls
ResponseContentType = application/vndmsexcel
responsewrite <table width=% border= >
responsewrite <tr>
responsewrite <th width=%><b>Name</b></th>
responsewrite <th width=%><b>Username</b></th>
responsewrite <th width=%><b>Password</b></th>
responsewrite </tr>
responsewrite <tr>
responsewrite <td width=%>Scud Block</td>
responsewrite <td width=%>scud@gazatemcom</td>
responsewrite <td width=%>mypassword</td>
responsewrite </tr>
responsewrite </table>
%>