How to read Excel files with ASP

Source: Internet
Author: User
Tags count sql xsl file
In enterprise-class applications, we often need to operate on execl, such as reading execl inside the data, inserting data into the execl. First, the operation of the EXECL to note: 1, the configuration of server-side office in the case of Ms Windows2000+iis, there are no special requirements for a version of Execl,office installed on the server side of MS Office. 2.   Server-side Distributed COM configuration execute the "DCOMCNFG" command, select the Microsoft execl application-> Properties-> "Security"-> the Applications page, and choose "Use custom access rights" to add ' Everyone ' permission. Second, first of all, will take advantage of ASP to read EXECL data (do not create DSN): We can view the entire. xsl file as a database, Sheet1, Sheet2, etc., respectively, as a separate table, the A1, B1, C1 、... N1 as a table field. --Establish a Connection object instance 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 filename ") conn. Open strconn--Establishes the DataSet object RS and queries the data Set rs = Server.CreateObject ("ADODB. Recordset ") sql=" select * from [sheet1$] "Rs. Open sql,conn,2,2 Concrete Example: 1, establish a table Sheet1 (database name is students)
StudentID Name Language Mathematical Physical Chemical Geographical
1 Li Xieqing 83 84 76 95 66
2 Feng Jiang 87 96 82 100 81
3 Wu Xiaoxia 76 43 37 60 82
4 Shian Hui 80 77 63 71 63
5 Cai Haifei 89 63 92 86 67
2, query and display the contents of the table Sheet1 code <% Dim conn Dim strconn 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 strconn Set rs = Server.CreateObject ("ADODB. Recordset ") sql=" select * from [sheet1$] "Rs. Open sql,conn,2,2%> <center> <table border= "1" > <tr> <% for i=0 to Rs. Fields.count-1%> <td bgcolor= "#0099FF" ><%=rs (i). Name%></td> <% Next%> </tr> <% do, not Rs. EOF%> <tr> <% for i=0 to Rs. Fields.count-1%> <td><%=rs (i)%></td> <% next%> </tr> <% Rs. MoveNext Loop rs.close set rs=nothing strconn.close set strconn=nothing%> </table></center>

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.