急~~!!!請問如何將ASP網頁用excel格式存盤(作為excel格式打開也好),謝謝大家了:)
更新时间: 周三, 11/14/2007 - 10:31
我寫了一個生產數據匯總的asp網頁,想轉換為excel格式打開或存盤,我用一下語句實現,可程序報錯,
<%
server.scripttimeout=72000
lexcel=request("pexcel")
if lexcel="1" then
response.buffer=true
response.contenttype ="application/vnd.ms-excel"
end if%>
錯誤提示為
the connection used this web site are expired.
or you are not sign-in to the system.
其中參數lexcel在點擊聯結時賦值為"1"。
参考文章:
<%@ language=vbscript %>
<%
response.buffer = true
response.contenttype = "application/vnd.ms-excel"
%>
<table border="1">
<tr>
<th>项目 a</th>
<th>项目 b</th>
<th>合计</th>
<th>项目 c</th>
<th>项目 d</th>
<th>合计</th>
</tr>
<tr>
<td height="30"><%=request.form("aa")%></td>
<td>3</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td><font color="red">=sum(a2:e2)*100</font></td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td colspan="4"><font color="red">=sum(a3:b3)+f2</font></td>
</tr>
</table>
或者使用创建 excel-application 对象的方法在服务器端生成 excel 文件也可以。
实在不行的话,生成一个文本文件,
数据间用逗号分隔,后缀用 csv ,
这种文件默认是用 excel 打开的!
<%@language="vbscript" codepage="936"%>
<%
path=trim(request.form("path"))
names=trim(request.form("name"))
files=path&names
if path<>"" and names<>"" then
set fs = server.createobject("scripting.filesystemobject")
filename = files
if fs.fileexists(filename) then
fs.deletefile(filename)
end if
set myfile = fs.createtextfile(filename,true)
set fs=nothing
response.write(files&"保存成功!")
else
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form action="index.asp" method="post" name="form1">
<p>路 径:
<input name="path" type="text" id="path">
</p>
<p>文件名:
<input name="name" type="text" id="name">
</p>
<p>
<input type="submit" name="submit" value="提交">
</p>
</form>
</body>
</html>
<%
end if
%>
网站导航