zoukankan      html  css  js  c++  java
  • Asp 导出Excel

    <%
    Dim xlWorkSheet
    Dim xlApplication
    Set xlApplication = Server.CreateObject("Excel.Application")
    xlApplication.Visible = False
    xlApplication.Workbooks.Add
    Set xlWorksheet = xlApplication.Worksheets(1)
    set oRS=Server.CreateObject("ADODB.Recordset")
    if Request("ImportExcel")="ImportExcel" then
      'If Response.IsClientConnected Then 
    '  Response.Flush 
    '  Else 
    '  Response.End
    '  End If
      Response.Expires = 0
      Response.Expiresabsolute = Now() - 1
      Response.AddHeader "Content-type","application/octet-stream"
      Response.AddHeader "Accept-Ranges","bytes"
      Response.AddHeader "Content-Disposition","attachment; filename=kl178exp.xls"
      'Response.ContentType = "application/msexcel"
      sql =session("SQL")  
      oRS.open sql,conns,1,3,1
      xlWorksheet.Cells(1,1).Value = "用户名"
      xlWorksheet.Cells(1,2).Value = "真实姓名"
      xlWorksheet.Cells(1,3).Value = "用户类型"
      xlWorksheet.Cells(1,4).Value = "注册时间"
      xlWorksheet.Cells(1,5).Value = "首次登录时间"
      xlWorksheet.Cells(1,6).Value = "最后登录时间"
      xlWorksheet.Cells(1,7).Value = "使用频率"
      xlWorksheet.Cells(1,8).Value = "停留时间"
      xlWorksheet.Cells(1,9).Value = "券商名称"
      xlWorksheet.Cells(1,10).Value = "业务员"
      xlWorksheet.Cells(1,1).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,2).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,3).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,4).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,5).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,6).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,7).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,8).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,9).Interior.ColorIndex = 16
      xlWorksheet.Cells(1,10).Interior.ColorIndex=16
      xlWorksheet.Cells(1,4).ColumnWidth=20
      xlWorksheet.Cells(1,5).ColumnWidth=20
      xlWorksheet.Cells(1,6).ColumnWidth=20
      
      iRow = 2
      If Not oRS.EOF Then
       Do Until oRS.EOF
      xlWorksheet.Cells(iRow,1).Value = oRS("UserName")
      xlWorksheet.Cells(iRow,2).Value = oRS("realName")
      xlWorksheet.Cells(iRow,3).Value = GetUserType(oRS("Usertype"))
      xlWorksheet.Cells(iRow,4).Value = FormatDate(oRS("RegisterTime"))
      xlWorksheet.Cells(iRow,5).Value = FormatDate(oRS("FirstLoginTime"))
      xlWorksheet.Cells(iRow,6).Value = FormatDate(oRS("LastLoginTime"))
      xlWorksheet.Cells(iRow,7).Value = oRS("UsedGroup")
      xlWorksheet.Cells(iRow,8).Value = oRS("UsedTime")
      xlWorksheet.Cells(iRow,9).Value = GetCompanyNameByID(oRS("CompanyID"))
      xlWorksheet.Cells(iRow,10).Value =oRS("introducer")
      iRow = iRow + 1
      oRS.MoveNext
      Loop
      End If
       rannum=int(1000*rnd)
       YoureIp=trim(Request.ServerVariables("REMOTE_ADDR"))
       YoureIp=left(YoureIp,len(YoureIp)-4)
       YoureIp=replace(YoureIp,".","")
      rndfile=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum&YoureIp
      strFile = rndfile
      xlWorksheet.SaveAs Server.MapPath(strFile & ".xls")
      xlApplication.Quit
      'Close the Workbook
      Set xlWorksheet = Nothing
      Set xlApplication = Nothing
      response.Redirect(strFile & ".xls")
    end if

    %>

  • 相关阅读:
    ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 —— 小车按键启动和蜂鸣器报警
    ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 —— 小车指定花式动作
    ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 —— 小车指定花式动作
    ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 —— 小车指定花式动作
    ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 —— 小车前后左右综合实验
    ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 —— 小车前后左右综合实验
    ZYAR20A 亚克力2驱 蓝牙 298寻迹避障机器人 —— 小车前后左右综合实验
    asp中设置session过期时间方法总结
    asp中设置session过期时间方法总结
    ASP.NET关于Session_End触发与否的问题
  • 原文地址:https://www.cnblogs.com/xffy1028/p/2344342.html
Copyright © 2011-2022 走看看