asp生成excelasp

/ / 2018-06-02   阅读:2496
Dim xlWorkSheet Dim xlApplication Set xlApplication = Server.CreateObject("Excel.Application") xlApplication.Visible = False xlApplication.DisplayAlerts=False xlApplication.Workbooks.Add Set xlW...
Dim xlWorkSheet
Dim xlApplication
Set xlApplication = Server.CreateObject("Excel.Application")
xlApplication.Visible = False
xlApplication.DisplayAlerts=False
xlApplication.Workbooks.Add
Set xlWorksheet = xlApplication.Worksheets(1)
set oRS=Server.CreateObject("ADODB.Recordset")
'if Request("ImportExcel")="ImportExcel" then
  randomize
  rannum=int(90000*rnd)+10000
   
  rndfile=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum
  strFile = rndfile

  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="&strFile&".xls"
  'Response.ContentType = "application/vnd.ms-excel"
  sql="select a.out_trade_no,a.total_fee,a.orderDate,b.realname,b.addr,b.postcode,b.tel from Np_Order a inner join [Np_User] b on a.userId=b.id order by a.id asc"
  oRS.open sql,conn,1,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,11).Value = "起始订期"
  xlWorksheet.Cells(1,12).Value = "截止订期"
  xlWorksheet.Cells(1,13).Value = ""
  xlWorksheet.Cells(1,14).Value = "折扣类型"
  xlWorksheet.Cells(1,15).Value = "金额"
  xlWorksheet.Cells(1,16).Value = "站名"
  xlWorksheet.Cells(1,17).Value = "投递段"
  xlWorksheet.Cells(1,18).Value = "投递方式"
  xlWorksheet.Cells(1,19).Value = "投递类型"
  
  xlWorksheet.Cells(1,6).ColumnWidth=30
  xlWorksheet.Cells(1,2).ColumnWidth=20
  xlWorksheet.Cells(1,11).ColumnWidth=10
  xlWorksheet.Cells(1,12).ColumnWidth=10
  

  iRow = 2
  If Not oRS.EOF Then
   Do while not oRS.EOF
  xlWorksheet.Cells(iRow,1).Value = ""
  xlWorksheet.Cells(iRow,2).NumberFormatLocal = "@"
  xlWorksheet.Cells(iRow,2).Value = CStr(oRS("out_trade_no"))
  xlWorksheet.Cells(iRow,3).Value = "报卡"
  xlWorksheet.Cells(iRow,4).Value = ""
  xlWorksheet.Cells(iRow,5).Value = Trim(oRS("realname"))
  xlWorksheet.Cells(iRow,6).Value = Trim(oRS("addr"))
  xlWorksheet.Cells(iRow,7).Value = Trim(oRS("postcode"))
  xlWorksheet.Cells(iRow,8).Value = Trim(oRS("tel"))
  xlWorksheet.Cells(iRow,9).Value = Trim(oRS("tel"))
  xlWorksheet.Cells(iRow,10).Value = "郑州晚报1年报刊定制"
  xlWorksheet.Cells(iRow,11).Value = FormatDateTime(oRS("orderDate"),2)
  xlWorksheet.Cells(iRow,12).Value = FormatDateTime(DateAdd("yyyy",1,oRs("orderDate")),2)
  xlWorksheet.Cells(iRow,13).Value = ""
  xlWorksheet.Cells(iRow,14).Value = ""
  xlWorksheet.Cells(iRow,15).Value = Trim(oRS("total_fee"))
  xlWorksheet.Cells(iRow,16).Value = ""
  xlWorksheet.Cells(iRow,17).Value = ""
  xlWorksheet.Cells(iRow,18).Value = ""
  xlWorksheet.Cells(iRow,19).Value = ""
  
    iRow = iRow + 1
    oRS.MoveNext
  Loop
  End If
  oRS.Close
  set oRS=nothing
  closeconn
  
  xlWorksheet.SaveAs Server.MapPath(strFile & ".xls")
  xlApplication.Quit
  'Close the Workbook
  Set xlWorksheet = Nothing
  Set xlApplication = Nothing

  Response.Write("生成网址:"&strFile&".xls")
'end if

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈