Excel export using ASP

Source: Internet
Author: User

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

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.