Export data from ASP to excel
--------------------------------------------------------------------------------
Add this sentence at the beginning
Response. contenttype = "application/vnd. MS-excel"
If the export result is blank, remove it.
Export ExcelCode
--------------------------------------------------------------------------------
<%
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 = "User table"
Excelbook. worksheets (1). cells (2, 1). value = "User ID"
Excelbook. worksheets (1). cells (2, 2). value = "login name"
Excelbook. worksheets (1). cells (2, 3). value = "Real Name"
Excelbook. worksheets (1). cells (2, 4). value = "password"
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" '. After the data is exported, it is saved as a file on disk D.
Export excelapp. application. Quit and exit Excel
Set excelapp = nothing 'unregister an Excel Object
%>
This is an example of reading data from an Excel table.
--------------------------------------------------------------------------------
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") = "January"
Oxls. Update
...
Oxls. Close
Set oxls = nothing