频道直达 - 学院 - 下载 - 交易 - 特效 - 字库 - 手册 -排名-工具- 繁體
网页教学网站开发 设为首页
加入收藏
联系我们
建站搜索: 常用广告代码   用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发设计技术教程 -> asp教程 -> 如何用asp把sqlserver数据转换为execl文件

如何用asp把sqlserver数据转换为execl文件

作者:未知  来源:转载  发布时间:2005-9-15 20:31:50  发布人:acx

减小字体 增大字体

1、ASP文件:

<%@ LANGUAGE="VBscript" %>
<%option explicit%>
<%
'EXAMPLE AS:把数据库中一个每天24小时在线人数放到一个EXCEL文件中去
'AUTHOR    :钢铁工人
'EMAIL     :hello_hhb@21cn.com
'DATE      :2001-3-25
'TEST      :在NT4,SP6,SQL SERVER 7.0,EXCEL2000中测试通过
%>
<HTML>
<HEAD>
<meta content="text/html; charset=gb2312" http-equiv="Content-Type">
<TITLE>生成EXCEL文件</TITLE>
</HEAD>
<body>
<a href="dbtoexcel.asp?act=make">生成在线人口的EXCEL</a>
<hr size=1 align=left width=300px>
<%
if Request("act") = "" then
else

  dim conn
  set conn=server.CreateObject("adodb.connection")
  conn.Open "test","sa",""
  'conn.Open Application("connstr")

  dim rs,sql,filename,fs,myfile,x,link
  
  Set fs = server.CreateObject("scripting.filesystemobject")
  '--假设你想让生成的EXCEL文件做如下的存放
  filename = "c:\online.xls"
  '--如果原来的EXCEL文件存在的话删除它
  if fs.FileExists(filename) then
    fs.DeleteFile(filename)
  end if
  '--创建EXCEL文件
  set myfile = fs.CreateTextFile(filename,true)


  
  Set rs = Server.CreateObject("ADODB.Recordset")
  '--从数据库中把你想放到EXCEL中的数据查出来
  sql = "select population,hourpos,datepos from populationperhour order by datepos,hourpos asc"
  rs.Open sql,conn
  if rs.EOF and rs.BOF then
  
  else
  
    dim strLine,responsestr
    strLine=""
      For each x in rs.fields
        strLine= strLine & x.name & chr(9)
      Next
    
      '--将表的列名先写入EXCEL
      myfile.writeline strLine

      Do while Not rs.EOF
      strLine=""
     
      for each x in rs.Fields
        strLine= strLine & x.value & chr(9)
      next
      '--将表的数据写入EXCEL
      myfile.writeline strLine

      rs.MoveNext
      loop
      
  end if

rs.Close
set rs = nothing
conn.close
set conn = nothing
set myfile = nothing
Set fs=Nothing

link="<A HREF=" & filename & ">Open The Excel File</a>"
Response.write link
end if
%>
</BODY>
</HTML>


2、数据库相关:

CREATE TABLE [populationperhour] (
    [population] [int] NOT NULL ,
    [hourpos] [int] NOT NULL ,
    [datepos] [datetime] NOT NULL
);
insert into populationperhour values('936','1','2001-1-11');
insert into populationperhour values('636','2','2001-1-11');
insert into populationperhour values('106','3','2001-1-11');
insert into populationperhour values('177','4','2001-1-11');
insert into populationperhour values('140','5','2001-1-11');
insert into populationperhour values('114','6','2001-1-11');
insert into populationperhour values('94','7','2001-1-11');
insert into populationperhour values('49','8','2001-1-11');
insert into populationperhour values('88','9','2001-1-11');
insert into populationperhour values('215','10','2001-1-11');
insert into populationperhour values('370','11','2001-1-11');
insert into populationperhour values('550','12','2001-1-11');
insert into populationperhour values('629','13','2001-1-11');
insert into populationperhour values('756','14','2001-1-11');
insert into populationperhour values('833','15','2001-1-11');
insert into populationperhour values('923','16','2001-1-11');
insert into populationperhour values('980','17','2001-1-11');
insert into populationperhour values('957','18','2001-1-11');
insert into populationperhour values('812','19','2001-1-11');
insert into populationperhour values('952','20','2001-1-11');
insert into populationperhour values('1379','21','2001-1-11');
insert into populationperhour values('1516','22','2001-1-11');
insert into populationperhour values('1476','23','2001-1-11');
insert into populationperhour values('1291','24','2001-1-11');
insert into populationperhour values('1028','1','2001-1-12');
insert into populationperhour values('687','2','2001-1-12');
insert into populationperhour values('462','3','2001-1-12');
insert into populationperhour values('317','4','2001-1-12');
insert into populationperhour values('221','5','2001-1-12');
insert into populationperhour values('158','6','2001-1-12');
insert into populationperhour values('127','7','2001-1-12');
insert into populationperhour values('81','8','2001-1-12');
insert into populationperhour values('96','9','2001-1-12');
insert into populationperhour values('192','10','2001-1-12');
insert into populationperhour values('380','11','2001-1-12');
insert into populationperhour values('629','12','2001-1-12');
insert into populationperhour values('745','13','2001-1-12');
insert into populationperhour values('964','14','2001-1-12');
insert into populationperhour values('1012','15','2001-1-12');
insert into populationperhour values('1050','16','2001-1-12');
insert into populationperhour values('1135','17','2001-1-12');
insert into populationperhour values('1130','18','2001-1-12');
insert into populationperhour values('894','19','2001-1-12');
insert into populationperhour values('1026','20','2001-1-12');
insert into populationperhour values('1430','21','2001-1-12');
insert into populationperhour values('1777','22','2001-1-12');
insert into populationperhour values('1759','23','2001-1-12');
insert into populationperhour values('1697','24','2001-1-12');

将本文收藏到QQ书签与更多好友分享
[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 要10G免费网络硬盘的请进..
· 通过google 赶快来赚美金..
· 注册码大全十
· 头像-qq头像(qq新头像)4..
· 让你轻松架设FTP服务器1..
· 注册码大全三
· 梦幻背景图片7
· 卡通动物图片6
· 网页制作素材-按钮素材2..
· 让你轻松架设FTP服务器5..
· 风景图片8
· 注册码大全九
· 让你轻松架设FTP服务器2..
关注此文读者还看过
· 浅谈asp编程中的测试打印..
· 节日网上支付谨防密码被..
· 如何在ASP.Net中取得环境..
· 轻松打造Flash帧速率测试..
· ASP学习:urldecode 方法..
· PHP调用三种数据库的方法..
· 利用SQL语言有没有办法查..
· WML教程:文本框控件(I..
· 用JavaScript实现利用FL..
· PHP中如何在输出内容后再..
· web.config 简单介绍
· 算术操作符
· 为ASP.NET控件加入快捷菜..
· Photoshop打造仲夏夜霓虹..
· 网游实名与防沉迷四季度..
· AS基础精典教程 第五章 ..
相关文章
· 如何用asp把sql server數據..
· 大家看看如何用asp操作Orac..
· 如何用Asp动态生成xml文件
· 如何用ASP编写网站统计系统..
· 如何用ASP编写网站统计系统..
· 如何用ASP编写网站统计系统..
· Flash中如何用AS实现帧反播..
· 如何用asp进行base64加密
· 如何用ASP将一大段文字中的..
· 如何用ASP编写网站统计系统..
· 如何用ASP编写网站统计系统..
· 如何用ASP编写网站统计系统..
· 如何用ASP编写网站统计系统..
· 如何用ASP建立图表
· 如何用Asp判断你的网站的虚..
· 如何用ASP创建日志文件
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
粤ICP备05092265号