ASP Excel export/import access database (code + instance download)

Source: Internet
Author: User
Tags id3 import database

Excel export Function

<%
Sub exporttoexcel

Response. contenttype = "application/vnd. MS-excel"
Response. addheader "content-disposition", "attachment?filename=results.xls"
Response. Write "<body>"
Response. Write "<Table border = 1>"

Call writetabledata

Response. Write "</table>"
Response. Write "</body>"
Response. Write "

End sub
%>

Import database in Excel

<%
Dim filename
Filename = "excel.xls" ': get the file name. It is specified by the project manager and the path is fixed in a virtual path.
Dim Conn, RS
Set conn = Createobject ("ADODB. Connection ")
Conn. Open "driver = {Microsoft Excel Driver (*. xls )};"&_
"Driverid = 790 ;"&_
"DBQ =" & server. mappath ("" & filename &"")&";"&_
"Defaultdir = G :/"

Set rs = Createobject ("ADODB. recordset ")
Rs. Open "select * from [sheet1 $]", Conn, 2, 2
If Rs. EOF then
Response. Write "no records in the Excel table"
Else
Set conndb = server. Createobject ("ADODB. Connection ")
Dbpath = server. mappath ("Excel. mdb ")
'Response. Write dbpath
Conndb. Open "driver = {Microsoft Access Driver (*. mdb)}; DBQ =" & dbpath
Set rsdb = server. Createobject ("ADODB. recordset ")
Sqldb = "select * from Excel"
Rsdb. Open sqldb, conndb, 1, 3
Do while not Rs. EOF 'reads data cyclically
Rsdb. addnew
Rsdb ("FILENAME") = RS (0)
Rsdb ("id1") = RS (1)
Rsdb ("ID2") = RS (2)
Rsdb ("ID3") = RS (3)
Rsdb ("ID4") = RS (4)
Rs. Update
Rsdb. movenext
Rs. movenext
Loop
'Response. Redirect filename
End if
Rsdb. movefirst
If rsdb. EOF then
Response. Write "no records in the Database"
Else
Do while not rsdb. EOF
Response. Write rsdb ("FILENAME ")&""
Response. Write rsdb ("id1 ")&""
Response. Write rsdb ("ID2 ")&""
Response. Write rsdb ("ID3 ")&""
Response. Write rsdb ("ID4 ")&""
Response. Write "<br>"
Rsdb. movenext
Loop
End if
Rs. Close
Set rs = nothing
Set conn = nothing
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.