ASP Read EXCEL2000 's article

Source: Internet
Author: User
Tags dsn header table name
Excel needs to read Excel payroll with ASP because of work, so I found some information on the Internet.
The following program is written to you:
<%
' =====================asp read Excel notes ===========================
' I "Excel97 or Excel2000 generated xls file (book) as a database, where each worksheet (sheet) as a database table
' II ADO assumes the first behavior field name in Excel. So the scope of your definition must include the first line of content
' III ' the row header (that is, the field name) in Excel cannot contain numbers. Excel drivers can make mistakes when encountering this problem. For example, your row header is named "F1."
' IIII If you have a column in your Excel spreadsheet that contains both text and numbers, then Excel's ODBC driver will not be able to handle this line of data types, you have to ensure that the data type of the column is consistent
' E-mail:kaxue@hotmail.com qq:484110 HOMEPAGE:www.Flyday.net
' Finishing Time: Thursday, May, 2002 5:54 PM WIN2000SERVER+IIS5-Test Pass
'===================================================================

Dim Conn,driver,dbpath,rs
' Create a Connection object
Set Conn = Server.CreateObject ("ADODB. Connection ")
Driver = "Driver={microsoft Excel Driver (*.xls)};"
DBPath = "dbq=" & Server.MapPath ("Test.xls")
' Invoke the Open method to open the database
Conn.Open Driver & DBPath

' DSN connection method
' Conn.Open ' dsn=test '
' Note that the table name must be written in the "[Table name $]" below.
Sql= "SELECT * from [sheet1$] where serial number = 0"
Set Rs=conn.execute (SQL)

IF rs.eof and Rs.bof Then
Response.Write "did not find the data you need!!"
Else

Do as not rs.eof

Response.Write Rs ("name")

Rs.movenext
Loop
End IF

Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
' Response.Write ' Success! "
%>



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.