<!--#include file="../Include/Const.Asp" -->
<!--#include file="../Include/ConnSiteData.Asp" -->
<!--#include file="../CheckAdmin.Asp"-->
<%  
 
dim s,sql,filename,fs,myfile,x 
Set fs = server.CreateObject("scripting.filesystemobject")
'--假设你想让生成的EXCEL文件做如下的存放 
filemember="../xls/易享客户管理系统通讯录.xls"

filename = Server.MapPath(filemember)
'--如果原来的EXCEL文件存在的话删除它  
if fs.FileExists(filename) then
   fs.DeleteFile(filename)
end  if
'--创建EXCEL文件  
set myfile = fs.CreateTextFile(filename,true)
Set rstData= Server.CreateObject("ADODB.Recordset")
'--从数据库中把你想放到EXCEL中的数据查出来
'Sql="select RealName as 姓名,[position] as 职务,Telephone as 办公电话,Mobile as 手机号码,Email as 邮箱 from Zqj_Members where Working order by ID desc"
sql="SELECT Zqj_Members.RealName as 姓名,Zqj_DepartmentSort.SortName as 部门,Zqj_Members.[position] as 职务,Zqj_Members.Telephone as 办公电话,Zqj_Members.Mobile as 手机号码,Zqj_Members.Email as 邮箱 FROM Zqj_Members INNER JOIN Zqj_DepartmentSort ON Zqj_Members.SortPath=Zqj_DepartmentSort.SortPath;"
rstData.Open sql,conn,1,3
'Set rstData=conn.Execute (Sql)
if rstData.EOF and rstData.BOF then  
response.Write "<script language='JavaScript'>alert('没有资料!');" & "history.back()" & "</script>"
else 
    dim  trLine,responsestr
    strLine=""
   For each x in rstData.fields
       strLine = strLine & x.name & chr(9)
   Next  
        'strLine=strLine & "是否合作" & chr(9)
 '--将表的列名先写入EXCEL  
   myfile.writeline strLine 
'用同样的方法将每条记录的所有值存入变量，再写入文件中：
    Do while Not rstData.EOF
        strLine=""
        for each x in rstData.Fields
            strLine = strLine & x.value & chr(9)
        next
        myfile.writeline strLine
        rstData.MoveNext
    loop
  '写入备注信息
   strLine="本次导出操作时间"&now()&""
   myfile.writeline strLine
end if  
Response.Write  "已成功为您导出最新通讯录资料，点击下载 <a href="""&filemember&""" target=""_blank"">易享客户管理系统通讯录.xls</a>"
rstData.Close  
set rstData = nothing
Conn.Close
Set Conn = nothing
%>