日期:2014-05-17  浏览次数:21232 次

查询出来的记录怎么导入Excel?急,在线等!
我现在有一个查询出来的表单,想通过点击一个按钮,把表单内的数据和格式都导入到Excel内,请问各位高手怎么实现!!

------解决方案--------------------
http://blog.csdn.net/itzhiren/archive/2006/06/24/828956.aspx
ASP操作Excel技术总结
------解决方案--------------------
http://feb-.blog.163.com/blog/static/16577892007035026162

这个是最简单的
------解决方案--------------------
<%
Response.Buffer = TRUE
Response.AddHeader "Content-Disposition ", "attachment; filename=查询报表 "&replace(now(), ": ", "- ")& ".xls "
Response.contentType= "application/vnd.ms-excel "
%>
<!--#include file= "inc/conn.asp "-->
<!--#include file= "admin.asp "-->
<%
dim sql,rs
sql= "select * from report "
set rs=conn.execute(sql)
%>
<table width= '437 ' border= '0 ' align= 'center ' cellpadding= '0 ' cellspacing= '1 ' id= "data ">
<tr style= "font-family: '宋体 '; font-size:14px; font-weight:bolder; "> <td width= '91 ' height= '30 ' > 姓名 </td>
<td width= '56 ' > 性别 </td>
<td width= '91 ' > 邮编 </td>
<td width= '108 ' > 工作电话 </td>
<td width= '85 ' > 传真 </td>
</tr>
<%
if rs.eof or rs.bof then

else
do while not rs.eof
%>
<tr> <td> <%=trim(rs( "name "))%> </td>
<td align= 'center '> <%=trim(rs( "sex "))%> </td>
<td> <%=trim(rs( "postalcode "))%> </td>
<td> <%=trim(rs( "workphone "))%> </td>
<td> <%=trim(rs( "fax "))%> </td>
</tr>
<%
rs.movenext
loop
%>
</table>
<%
end if
set rs=nothing
set conn=nothing
%>

------解决方案--------------------
<SCRIPT LANGUAGE= "javascript ">
<!--
function AutomateExcel()
{

// Start Excel and get Application object.
var oXL = new ActiveXObject( "Excel.Application ");
// Get a new workbook.
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var table = document.all.MainTable; //MainTable;为表格id
var hang = table.rows.length;

var lie = table.rows(0).cells.length;


// Add table headers going cell by cell.
for (i=0;i <hang;i++)
{
for (j=0;j <lie;j++)
{
oSheet.Cells(i+1,j+1).value = table.rows(i).cells(j).innerText;
}

}
oXL.Visible = true;
oXL.UserControl = true;
}
//-->
</SCRIPT>
<div align= "center ">
<input type= "BUTTON " name= "out_excel " onclick= "AutomateExcel(); " value= "导出到excel " class= "notPrint "> </div>