ASP具備動態輸出任一Office應用程序文件格式的功能在開始編寫代碼之前我們首先需要做的就是設置正確的文件類型因為浏覽器需要知道如何處理文件第二步是編輯文件名稱我們可以使用HTML和CSS來創建Word文檔或Excel文檔的樣式
下面這段例子代碼可用於在線創建Word文檔
以下是引用片段
<%
Response
ContentType =
application/msword
Response
AddHeader
Content
Disposition
attachment;filename=NAME
doc
???
response
Write(
Dotnetindex
com : <a href=
visit/
>http://www
dotnetindex
com
>Visit Site</a><br>
& vbnewline)
response
Write(
<h
>We can use HTML codes for word documents</h
>
)
response
Write (
<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
><%
Response
AddHeader
Content
Disposition
attachment;filename=members
xls
Response
ContentType =
application/vnd
ms
excel
response
write
<table width=
%
border=
>
response
write
<tr>
response
write
<th width=
%
><b>Name</b></th>
response
write
<th width=
%
><b>Username</b></th>
response
write
<th width=
%
><b>Password</b></th>
response
write
</tr>
response
write
<tr>
response
write
<td width=
%
>Scud Block</td>
response
write
<td width=
%
>scud@gazatem
com</td>
response
write
<td width=
%
>mypassword</td>
response
write
</tr>
response
write
</table>
%>
From:http://tw.wingwit.com/Article/program/net/201311/14969.html