asp匯出excel

來源:互聯網
上載者:User

asp匯出到excel

--------------------------------------------------------------------------------
在開頭加上這一句
Response.ContentType = "application/vnd.ms-excel"
如果匯出結果為空白的,那就去掉它

一下是匯出Excel代碼

--------------------------------------------------------------------------------
<%
set rs=server.createobject("adodb.recordset")
sql="select * from provinceinfo where 1=1"
rs.open sql,objconn,1,1
Set ExcelApp =CreateObject("Excel.Application")
ExcelApp.Application.Visible = True
Set ExcelBook = ExcelApp.Workbooks.Add
ExcelBook.WorkSheets(1).cells(1,1).value ="使用者表" 
ExcelBook.WorkSheets(1).cells(2,1).value = "使用者編號"
ExcelBook.WorkSheets(1).cells(2,2).value = "登陸名"
ExcelBook.WorkSheets(1).cells(2,3).value = "真實姓名"
ExcelBook.WorkSheets(1).cells(2,4).value = "密碼"
cnt =3
do while not rs.eof
ExcelBook.WorkSheets(1).cells(cnt,1).value = rs("provinceid")
ExcelBook.WorkSheets(1).cells(cnt,2).value = rs("province")
ExcelBook.WorkSheets(1).cells(cnt,3).value = rs("flag")
ExcelBook.WorkSheets(1).cells(cnt,4).value = rs("id")
rs.movenext
cnt = cint(cnt) + 1
loop
Excelbook.SaveAs "d:\yourfile.xls"   '這個是資料匯出完畢以後在D盤存成檔案
ExcelApp.Application.Quit    '匯出以後退出Excel
Set ExcelApp = Nothing    '登出Excel對象
%>

這是讀取Excel表中資料例子
--------------------------------------------------------------------------------
sConn1="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("..")&"\temp\"&sNewFileName & ";Extended Properties=""Excel 8.0;HDR=NO;"""
      oxls.Open "SELECT * FROM [sheet1$]",sConn1,1,3
      oxls.movenext
oxls("f11")="1月"
      oxls.update
...
      oxls.Close
Set oxls=nothing

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.