没有扩展类。你可以把数据以符号分隔开,以文本形式导入excel里

解决方案 »

  1.   

    你应该看得懂ASP吧,这里有篇ASP的文章,我以前试过,可以用的。将数据库里面的内容生成EXCEL
    1、ASP文件:<%@ LANGUAGE="VBSCRIPT" %>
    <%option explicit%>
    <%
    'EXAMPLE AS:把数据库中一个每天24小时在线人数放到一个EXCEL文件中去
    'AUTHOR    :钢铁工人
    'EMAIL     :[email protected]
    '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 ifrs.Close
    set rs = nothing
    conn.close
    set conn = nothing
    set myfile = nothing
    Set fs=Nothinglink="<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');
      

  2.   


    你可以用ODBC来实现。
      

  3.   

    你看这样形形,可以用jsp或servlet动态生成客户端脚本,如vbscript,在客户端脚本中调用MS做的接口,因为excel导入用的是标准的com组件,必须在客户端进行调用并执行导出,所以,也就必须用客户端脚本进行导出
      

  4.   

    你看这样形不形,可以用jsp或servlet动态生成客户端脚本,如vbscript,在客户端脚本中调用MS做的接口,因为excel导入用的是标准的com组件,必须在客户端进行调用并执行导出,所以,也就必须用客户端脚本进行导出
      

  5.   

    楼上用的asp代码是否只能把excel导出到web server上
      

  6.   

    czb(草中宝) 多谢你的建议,不过我是想把他存放到客户端的,另外我想最好能用jsp或者javabean来实现。
    lanren,你说的这种方法如果客户端没有装excel的时候有可能会出错吧,不过如果可以限定客户端配置的话,这个倒是个不错的idea.
    skyyoung(路人甲) 你说的这种方法我也曾想过,不过如果报表里面有些公式是们的好像就无能为力了吧.
    sharetop(天生不笨) 您能再讲的详细一些吗,您的意思是不是在服务器上创建一个odbc源指向一个excel文件。 
      

  7.   

    微软没有不知道,我有。[email protected]
      

  8.   

    就象显示word文档那样显示吧,有很多类似的ASP文章
      

  9.   

    asp能实现,jsp还有什么问题吗?
    你要存到客户端??那怎么可能?客户端会让你写?
      

  10.   

    xiaow(小为) 我需要写在客户端的,我想能不能那样,在服务器端写一个excel文件的以流的方式传送到客户端,让他下载到本地去,但不知道可不可行
      

  11.   

    再回答一次你的问题吧,在服务器端是不可能强行用HTTP协议把excel数据流推到客户端的,只能是是客户端先申请,然后服务器端发回excel数据流。其实在IE浏览器上显示服务器端的excel数据流是很简单的,参见http://www.csdn.net/expert/topic/328/328313.shtm
    可是如果是多用户多进程的时候怎么判断哪个文件对应哪个用户呢?放在服务器上主要是给用户下载的,你没有必要去判断是哪个用户吧,如果非要判断的话,你判断下远端请求的IP地址不就OK了吗?
      

  12.   

    我建议在客户端使用script直接打开excel,将数据写到excel的格子里,然后让excel自己保存。
      

  13.   

    czb说的不错。
    csv数据,Application/msexcel格式(MIMEType)即可。
    //response.setContentType("Application/msexcel"); 
      

  14.   

    如果是在服务器不是在MS的平台上,那么到那里去找生成excel的com对象,但是客房端如果想导出excel的话就一定是MS平台,当然如果客房端没有装excel的话可以转存为以逗号隔开的txt,
    所以,我觉得用客房端脚本地可行的