⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asp生成excel文件的问题.htm

📁 较为详细的介绍了asp自定义的各种函数,方便asp的各种开发.
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0055)http://www.51base.com/article/view_article.asp?id=78308 -->
<HTML lang=zh-cn><HEAD><TITLE>NB联盟</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type><LINK 
href="NB联盟35.files/style.css" rel=stylesheet>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY><!-- start page body -->
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 class=td id=position 
width=773>
  <TBODY>
  <TR>
    <TD class=shadow colSpan=2 height=20 width=262>&nbsp;&nbsp;<A 
      href="http://www.51base.com/"><IMG border=0 
      src="NB联盟35.files/logo1.gif"></A> </TD>
    <TD align=right width=505>
      <P align=left></P></TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 id=main width=770>
  <TBODY>
  <TR>
    <TD class=tdlbr vAlign=top>
      <TABLE align=center border=0 cellPadding=0 cellSpacing=0 id=welcome 
      style="TABLE-LAYOUT: fixed" width="98%">
        <TBODY>
        <TR>
          <TD style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" 
            vAlign=top><FONT color=red><B>文章标题</B></FONT><FONT color=red><B>: 
            asp生成excel文件的问题!! </B></FONT>
            <HR noShade SIZE=1>
            <BR>如何实现如下功能: 
            &nbsp;<BR>把用户从数据库中查询的结果生成excel格式的文件供用户下载!!有什么好的方案吗?谢谢解答,正确答案的全分! 
            &nbsp;<BR>--------------------------------------------------------------- 
            &nbsp;<BR>&nbsp;<BR>http://www.xxsky.com/article/view.asp?id=434 
            &nbsp; &nbsp;这里有一个例子 
            &nbsp;<BR>--------------------------------------------------------------- 
            &nbsp;<BR>&nbsp;<BR>将SQL &nbsp;Server里的数据转换成EXCEL文件: &nbsp;<BR>请参考: 
            &nbsp;<BR>http://expert.csdn.net/Expert/topic/1525/1525187.xml?temp=.7133295 
            &nbsp;<BR>--------------------------------------------------------------- 
            &nbsp;<BR>&nbsp;<BR>&lt;%@ &nbsp;LANGUAGE="VBSCRIPT" &nbsp;%&gt; 
            &nbsp;<BR>&lt;%option &nbsp;explicit%&gt; &nbsp;<BR>&lt;HTML&gt; 
            &nbsp;<BR>&lt;HEAD&gt; &nbsp;<BR>&lt;meta &nbsp;content="text/html; 
            &nbsp;charset=gb2312" &nbsp;http-equiv="Content-Type"&gt; 
            &nbsp;<BR>&lt;TITLE&gt;生成EXCEL文件&lt;/TITLE&gt; 
            &nbsp;<BR>&lt;/HEAD&gt; &nbsp;<BR>&lt;body&gt; &nbsp;<BR>&lt;a 
            &nbsp;href="dbtoexcel.asp?act=make"&gt;生成在线人口的EXCEL&lt;/a&gt; 
            &nbsp;<BR>&lt;hr &nbsp;size=1 &nbsp;align=left &nbsp;width=300px&gt; 
            &nbsp;<BR>&lt;% &nbsp;<BR>if &nbsp;Request("act") &nbsp;= &nbsp;"" 
            &nbsp;then &nbsp;<BR>&nbsp; &nbsp; &nbsp;Response.Write 
            &nbsp;"生成EXCEL文件" &nbsp;<BR>else &nbsp;<BR>&nbsp;<BR>dim 
            &nbsp;conn,strconn &nbsp;<BR>strconn="driver={SQL 
            &nbsp;Server};server=wen;uid=sa;pwd=;database=DB_Test" &nbsp;<BR>set 
            &nbsp;conn=server.CreateObject("adodb.connection") 
            &nbsp;<BR>conn.Open &nbsp;strconn &nbsp;<BR>&nbsp;<BR>dim 
            &nbsp;rs,sql,filename,fs,myfile,x &nbsp;<BR>&nbsp;<BR>Set &nbsp;fs 
            &nbsp;= &nbsp;server.CreateObject("scripting.filesystemobject") 
            &nbsp;<BR>'--假设你想让生成的EXCEL文件做如下的存放 &nbsp;<BR>filename &nbsp;= 
            &nbsp;Server.MapPath("online.xls") &nbsp;<BR>'--如果原来的EXCEL文件存在的话删除它 
            &nbsp;<BR>if &nbsp;fs.FileExists(filename) &nbsp;then 
            &nbsp;<BR>fs.DeleteFile(filename) &nbsp;<BR>end &nbsp;if 
            &nbsp;<BR>'--创建EXCEL文件 &nbsp;<BR>set &nbsp;myfile &nbsp;= 
            &nbsp;fs.CreateTextFile(filename,true) 
            &nbsp;<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>Set &nbsp;rs &nbsp;= 
            &nbsp;Server.CreateObject("ADODB.Recordset") 
            &nbsp;<BR>'--从数据库中把你想放到EXCEL中的数据查出来 &nbsp;<BR>sql &nbsp;= 
            &nbsp;"select &nbsp;* &nbsp;from &nbsp;Tb_Execl &nbsp;order &nbsp;by 
            &nbsp;id &nbsp;desc" &nbsp;<BR>rs.Open &nbsp;sql,conn &nbsp;<BR>if 
            &nbsp;rs.EOF &nbsp;and &nbsp;rs.BOF &nbsp;then 
            &nbsp;<BR>&nbsp;<BR>else &nbsp;<BR>&nbsp;<BR>dim 
            &nbsp;strLine,responsestr &nbsp;<BR>strLine="" &nbsp;<BR>For 
            &nbsp;each &nbsp;x &nbsp;in &nbsp;rs.fields &nbsp;<BR>strLine= 
            &nbsp;strLine &nbsp;&amp; &nbsp;x.name &nbsp;&amp; &nbsp;chr(9) 
            &nbsp;<BR>Next &nbsp;<BR>&nbsp;<BR>'--将表的列名先写入EXCEL 
            &nbsp;<BR>myfile.writeline &nbsp;strLine &nbsp;<BR>&nbsp;<BR>Do 
            &nbsp;while &nbsp;Not &nbsp;rs.EOF &nbsp;<BR>strLine="" 
            &nbsp;<BR>&nbsp;<BR>for &nbsp;each &nbsp;x &nbsp;in &nbsp;rs.Fields 
            &nbsp;<BR>strLine= &nbsp;strLine &nbsp;&amp; &nbsp;x.value 
            &nbsp;&amp; &nbsp;chr(9) &nbsp;<BR>next &nbsp;<BR>'--将表的数据写入EXCEL 
            &nbsp;<BR>myfile.writeline &nbsp;strLine 
            &nbsp;<BR>&nbsp;<BR>rs.MoveNext &nbsp;<BR>loop 
            &nbsp;<BR>&nbsp;<BR>end &nbsp;if &nbsp;<BR>&nbsp;<BR>rs.Close 
            &nbsp;<BR>set &nbsp;rs &nbsp;= &nbsp;nothing 
        &nbsp;<BR><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center border=0 cellPadding=2 cellSpacing=0 id=footer width=770>
  <TBODY>
  <TR>
    <TD align=middle class=tdt>
      <P align=center></P></TD></TR></TBODY></TABLE><BR></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -