ASP operations Excel, display data and statistical methods

Source: Internet
Author: User

This work is done by ASP operation Excel, the whole program is marked out every line, and then like to do in the blank. Now I've changed it. Dynamically displays the items for each row, and then displays the row by line, and finally makes a summary.

1, FSO find Excel file

<%
Dim fso,folder,file
Set fso  = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(Server.MapPath("data"))

Dim name
For Each file in folder.Files
name = fso.GetBaseName(file)
%>
<li><%=name%></li>
<%
Next
%>

2, connect the Excel file, get the name of the first sheet

<%
Create a Connection object
Set CONN_QC = Server.CreateObject ("ADODB. Connection ")
Driver = "Provider=Microsoft.Jet.OLEDB.4.0;"
Dbparm = "Extended properties=" "Excel 8.0; Hdr=yes;imex=1 "";
To open a database by calling the Open method
DBPath = "Data source=" & Server.MapPath ("Data\" & Table & ". xls") & ";" ' Note: The table variable here is the filename and can be obtained by the previous method
Conn_qc. Open Driver & DBPath & Dbparm
Get the name of the first sheet
Set RS=CONN_QC. OpenSchema (20)
TableName = RS ("table_name")
Rs. Close
Querying data
Sql= "SELECT * FROM [" & TableName & "]"

Response.Write (SQL)
' Set Rs=conn.execute (SQL)
Rs.Open sql, CONN_QC, 1, 1 ' Here you can solve the RecordCount-1 problem
If Rs.recordcount<>0 Then
%>
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" >
<tr>
<%for i=0 to Rs.fields.count-1%>
&LT;TD align= "center" valign= "Middle" bgcolor= "#F2F8FF" ><% =rs (i). Name%></td>
<%next%>
</tr>
<tr>
<%for i=0 to Rs.fields.count-1%>
&LT;TD align= "center" valign= "middle" class= "F" ><%=rs (i)%></td>
<%next%>
</tr>
</table>
<%
End If
Rs.close
Set rs=nothing
Conn_qc.close
%>

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.