读书人

asp数据导出,该怎么处理

发布时间: 2012-02-27 10:00:22 作者: rapoo

asp数据导出
我的代码:
<body>
<%
%>
<table cellPadding=0 cellSpacing=0 align=center width=100%>
<tr>
<th width="100%" style="text-align:center;">日志列表</th>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<TR>
<TD width="*">
<%
if session("flag") then
%>
搜索用户:
<select name="loginID">
<option value="">日志检索</option>
<%
sql="select * from [user] where loginID<>'admin' order by id"
set rs=conn.execute(sql)
while not rs.eof
%>
<option value="<%=rs("loginID")%>"<%if rs("loginID")=request.QueryString("loginID") then%> selected<%end if%>><%=rs("username")%></option>
<%
rs.movenext
wend
rs.close
%>
</SELECT>
搜索机房:
<select name="home">
<option value="">机房检索</option>
<%
sql="select distinct home from [summary]"
set rs=conn.execute(sql)
while not rs.eof
%>
<option value="<%=rs("home")%>"<%if rs("home")=request.QueryString("home") then%> selected<%end if%>><%=rs("home")%></option>
<%
rs.movenext
wend
rs.close
%>
</SELECT>
<%end if%>
日期:从
<input name="startDate" type="text" id="startDate" size="10" onClick="javascript:ShowCalendar('startDate')" value="<%=request.QueryString("startDate")%>"> <img style="cursor:hand;" src="images/date1.jpg" onClick="javascript:ShowCalendar('startDate')">

<input name="endDate" type="text" id="endDate" size="10" onClick="javascript:ShowCalendar('endDate')" value="<%=request.QueryString("endDate")%>"> <img style="cursor:hand;" src="images/date2.jpg" onClick="javascript:ShowCalendar('endDate')">
<input name="button" type="submit" class="button" id="button" onClick="location.href='worklog.asp?startDate='+document.all.startDate.value+'&endDate='+document.all.endDate.value<%if session("flag") then%>+'&loginID='+document.all.loginID.options[document.all.loginID.selectedIndex].value+'&home='+document.all.home.options[document.all.home.selectedIndex].value<%end if%>" value="搜索"></TD>
</TR>
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" style="word-break:break-all" >
<tr align=center>
<td>标题</td>
<td>所属机房</td>
<td>真实姓名</td>
<td>添加时间</td>
<td>提交IP</td>
<td>是否审核</td>
<td>审核日期</td>
<td>操作</td>
</tr>
<%
if session("flag")=false then
wherestr=" and a.loginID='"&session("loginID")&"'"


end if
if isdate(request("startDate")) then
wherestr=wherestr&" and datediff('d',a.insertTime,'"&request("startDate")&"')<=0"
end if

if isdate(request("endDate")) then
wherestr=wherestr&" and datediff('d',a.insertTime,'"&request("endDate")&"')>=0"
end if
if session("flag") then
if request("loginID")<>"" and request("loginID")<>"0" then
wherestr=wherestr&" and a.loginID='"&request("loginID")&"'"
end if

if request("home")<>"" then
wherestr=wherestr&" and a.home='"&request("home")&"'"
end if
end if

sql="select a.id,a.title,b.username,a.insertTime,a.IP,a.loginID,a.ischeck,a.checktime,a.home from [summary] a left join [user] b on a.loginID=b.loginID where 1=1 "&wherestr&" order by a.id desc"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
rs.pagesize=10
currentPage=Request.QueryString("page")
if not isnumeric(currentPage) then
currentPage=1
end if
currentPage=cint(currentPage)
if currentPage<1 then
currentPage=1
end if
if currentPage>rs.pagecount then
currentPage=rs.pagecount
end if
PageCounts=rs.pagecount
recordCounts=Rs.RecordCount
if not rs.eof then
rs.absolutepage=currentPage
for i=1 to rs.pagesize
if rs.eof then exit for
%>
<tr >
<td class="td1"><a href="logview.asp?id=<%=rs("id")%>"><%=rs("title")%></a></td>
<td align="center" class="td1"><%=rs("home")%></td>
<td align="center" class="td1"><a href="worklog.asp?loginID=<%=rs("loginID")%>"><%=rs("username")%></a></td>
<td align="center" class="td1"><%=rs("insertTime")%></td>
<td align="center" class="td1"><%=rs("IP")%></td>
<td align="center" class="td1"><%if rs("ischeck") then%>是<%else%>否<%end if%></td>
<td align="center" class="td1"><%=rs("checktime")%> </td>
<td align="center" class="td1"> <% if session("loginID")=rs("loginID") then%><%if formatdatetime(now,vbshortdate)=formatdatetime(rs("insertTime"),vbshortdate) then%><a href="worklogedit.asp?id=<%=rs("id")%>">修改</a><%end if%><%end if%>
<% if session("loginID")=rs("loginID") then%><%if formatdatetime(now,vbshortdate)=formatdatetime(rs("insertTime"),vbshortdate) then%> <a href="logdel.asp?id=<%=rs("id")%>" onClick="return confirm('您确认要删除吗')">删除</a><%end if%><%end if%> </td>
</tr>
<%
rs.movenext
next
end if
rs.close
conn.close
%>
</table>
<TABLE cellSpacing="0" cellPadding="0" width="100%" align="center" border="0">
<TBODY>
<TR>
<TD vAlign="center"><!--#include file="turnpage.asp" --></TD>
</TR>
</TBODY>
</TABLE>


</body>
</html>
帮我加个导出功能,谢谢!!

[解决办法]
Js导出Excel表格

写在form标签之上(引用打印控件)
<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" VIEWASTEXT></object>
<input id="Button2" type="button" value="导出Excel"
onclick="AutomateExcel('rp');" class="btnstyle"/>

function AutomateExcel(tid1) {

if (!document.getElementById(tid1)) {
alert("请您等待加载成报表后导数据!");
}
else {
try {

var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel = document.body.createTextRange();
sel.moveToElementText(document.getElementById(tid1));
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
oXL = null;
sel.execCommand("Unselect");
}
catch (e) {
alert("请您安装微软Excel办公组件及完全开放ActiveX,或询问系统管理员!");
}
}
}

说明:给你的table加个id,OnClick中的rp就是你的id.

读书人网 >ASP

热点推荐