Use ADO to Excel's data query

zhaozj2021-02-16  51

ASP data on the basic operation of Excel

Execl97 / 2000 / XP is one of the members of the MS Office office software. In enterprise applications, we often need to operate EXECL, such as reading data in Execl, inserting data into Execl.

1. Matters that do EXECL should be noted:

1, server-side OFFICE configuration

Take MS Windows2000 IIS as an example, to install one of the members of MS Office in the server side Execl, office version has no special requirements.

2, server-side distributed COM configuration

Execute the "DCMCNFG" command, select the "Microsoft Execl Application" -> "Properties" -> "Security" -> "Properties" -> "Use Custom Access Permissions" to add "Everyone" permission to use Custom Access .

Second, first, first use the ASP to read the data of EXECL (not established DSN):

We can see the entire .xsl file as a database, sheet1, sheet2, etc., respectively, see a separate table, regarding the A1, B1, C1, ... N1 as the field.

- Establish an example of connection object Execlconn

SET EXECLCONN = Server.createObject ("AdoDb.Connection")

- Open the database using the OPEN method

StrConn = "driver = {Microsoft Excel Driver (* .xls)};" & _

"Driverid = 790; dbq =" & server.mappath ("XLS file name")

Conn.open straconn

- Establish data set object RS and query data

SET RS = Server.createObject ("AdoDb.Recordset")

SQL = "SELECT *" "

RS.Open SQL, CONN, 2, 2

Specific example:

1. Create a table sheet1 (Database name to stayents)

StudentID

Name

Language

Numerology

Physical

Chemical

Ground

1

Li Xueqing

83

84

76

95

66

2

Feng Jiang

87

96

82

100

81

3

Wu Xiaoxia

76

43

37

60

82

4

Zou Yadong

80

77

63

71

63

5

Cai Haifei

89

63

92

86

67

2, query and display the code for the table sheet1 content

<%

DIM Conn

DIM STRCONNNNNNN

DIM RS

DIM SQL

Set conn = server.createObject ("adoDb.connection")

StrConn = "driver = {Microsoft Excel Driver (* .xls)};" & _

"Driverid = 790; dbq =" & server.mappath ("students.xls")

Conn.open straconn

SET RS = Server.createObject ("AdoDb.Recordset")

SQL = "SELECT *" "

RS.Open SQL, CONN, 2, 2

%>

<%

For i = 0 to rs.fields.count-1

%>

<%

For i = 0 to rs.fields.count-1

%>

<% = rs (i) .Name%> <%

NEXT

%>

<%

Do While Not Rs.eof

%>

<% = rs (i)%>

<%

NEXT

%>

<%

rs.movenext

Loop

Rs.close

SET RS = Nothing

Strconn.close

SET STRCONN = Nothing

%>

3, run results

转载请注明原文地址:https://www.9cbs.com/read-23261.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.046, SQL: 9