在asp中如何把页面中的表格保存成word

 我来答
90后回村房屋改造
2014-04-06 · TA获得超过148个赞
知道小有建树答主
回答量:218
采纳率:0%
帮助的人:139万
展开全部
导EXCEL行不行??

我自己写的
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../style/manage.css" rel="stylesheet" type="text/css">
<!--#include file=../include/conns.asp-->
<!--#include file=../include/inc2.asp-->
<!--#include file=../include/md5.asp-->
</head>
<body>
<div style="display:none;">
</div>
<%'////////////////////////////////////////////////FSO操作/////////////////////////////////////
'判断文件夹是否存在
Function FolderExits(Folder)
Folder=Server.Mappath(Folder)
Set FSO= Server.CreateObject("Scripting.FileSystemObject")
IF FSO.FolderExists(Folder) Then
FolderExits=true
Else
FolderExits=false
End IF
End Function
'判断文件是否存在
Function FileExits(FileName)
FileName=Server.Mappath(FileName)
Set FSO= Server.CreateObject("Scripting.FileSystemObject")
IF FSO.FileExists(FileName) Then
FileExits=true
Else
FileExits=false
End IF
End Function
'创建文件夹
Function CreateFolder(Folder)
on error resume next
Folder=Server.Mappath(Folder)
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
FSO.CreateFolder(Folder)
if err>0 then
err.clear
CreateFolder=False
else
CreateFolder=True
end if
End function
'创建文件
Function CreateFile(FileName,Content)
on error resume next
FileName=Server.Mappath(FileName)
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
set fd=FSO.createtextfile(FileName,true)
fd.writeline Content
if err>0 then
err.clear
CreateFile=False
else
CreateFile=True
end if
End function
'删除文件
function DeleteFile(FileName)
on error resume next
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
if FSO.FileExists(FileName) then
FSO.DeleteFile FileName,true
end if
if err>0 then
err.clear
DeleteFile=False
else
DeleteFile=True
end if
end function
'删除文件夹
function DeleteFolder(Folder)
on error resume next
Folder=server.MapPath(Folder)
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
if FSO.FolderExists(Folder) then
FSO.Deletefolder Folder,true
end if
if err>0 then
err.clear
Deletefolder=False
else
Deletefolder=True
end if
end function
%>
<%if request("t")="yhq" then
dim sql,filepath,fs,myfile,x,link

Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放
'temp=Server.MapPath("untitled2.asp") '获取index.asp主页所在路径。
' path=Left(temp,len(temp)-9) '获取路径字符串。
'filename = "books.xls" '指定Excel文件名。
filepath = Server.MapPath("excel/"&request.Cookies("mdsusername")&".xls") '生成Excel文件名及路径。
'--如果原来的EXCEL文件存在的话删除它
if fs.FileExists(filepath) then
fs.DeleteFile(filepath) '删除已经存在的同名文件。
end if
'--创建EXCEL文件
m_username=request.Cookies("mdsusername")
set myfile = fs.CreateTextFile(filepath,true)
Set rs = Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
if request("action")="search" then
if request("id")=1 then
Sql="select * from quanlist where q_m_id='"&m_username&"' and q_ok=0 order by q_time DESC"
else
Sql="select * from quanlist where q_m_id='"&m_username&"' and q_ok=1 order by q_time DESC"
end if
else
Sql="select * from quanlist where q_m_id='"&m_username&"' order by q_time DESC"
end if
rs.Open sql,conn,1,3

recnum=rs.recordcount '获取记录数。

if rs.EOF and rs.BOF then
else
'######################开始写入###################
dim strLine,responsestr
strLine=""
fieldnum=0
myfile.writeline chr(9)&chr(9)&"优惠券领取使用情况表"'此处可定义Excel标题
'For each x in rs.fields
' strLine= strLine & x.name & chr(9) 'chr(9)是指的水平方向上的制表符。
fieldnum=fieldnum+1 '获取字段数。
'Next
strLine="使用状态"& chr(9)&"用户名"&chr(9)&"领取时间"&chr(9)&"使用时间"&chr(9)&"联系方式"
'--将表的列名先写入EXCEL
myfile.writeline strLine
Do while Not rs.EOF
strLine=""
if rs("q_ok")=0 then
strLine="未使用"& chr(9)
else
strLine="已使用"& chr(9)
end if
if checkusername(request.Cookies("mdsusername"),rs("q_weixinnumber"))<>"" then
strLine=strLine&checkusername(request.Cookies("mdsusername"),rs("q_weixinnumber"))& chr(9)
else
strLine=strLine&rs("q_weixinnumber")& chr(9)
end if
strLine=strLine&rs("q_time")& chr(9)
strLine=strLine&rs("q_oktime")& chr(9)
strLine=strLine&checkuserphone(request.Cookies("mdsusername"),rs("q_weixinnumber"))&chr(9)

myfile.writeline strLine
rs.MoveNext
loop

end if
rs.Close
set rs = nothing
conn.close
set conn = nothing
set myfile = nothing
Set fs=Nothing
'读取写入信息此操作本地成功远程提示没有'CreateObject'权限
set objExcelApp = CreateObject("Excel.Application")
objExcelApp.DisplayAlerts = false '不显示警告
objExcelApp.Application.Visible = false '不显示界面
objExcelApp.WorkBooks.Open(filepath)
set objExcelBook = objExcelApp.ActiveWorkBook
set objExcelSheets = objExcelBook.Worksheets
set objExcelSheet = objExcelBook.Sheets(1)
response.write "<table border='1' style='border-collapse: collapse' bordercolor='#000000'>"
for i=1 to recnum+1
response.write "<tr>"
for j=1 to fieldnum
If i=1 Then
response.write "<td bgcolor=#006699><font color=#FFFFFF>"&objExcelSheet.Cells(i,j).value&chr(9)&"</font></td>"
Else
response.write "<td>"&objExcelSheet.Cells(i,j).value&chr(9)&"</td>"
End If
next
response.write "</tr>"
next
response.write "</table>"
objExcelApp.Quit ' 一定要退出
set objExcelApp = Nothing
response.Write "<div style='width:80%;margin:20% 10% 0 10%' align='center'>生成Excel文件成功,点击"
Response.Write "<a href='excel/"&request.Cookies("mdsusername")&".xls' target='_blank'>下载</a>"
response.Write " "
response.Write "<a href='#' onclick='javascript:window.history.go(-2)'>返回</a></div>"
end if%>
</body>
</html>
你研究下
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式