A function of using ADO to display the contents of Excel files in ASP

Source: Internet
Author: User

DDDGGG [Original]

Function Switchexcelinfo (Xlsfilename)

Dim Xlsstr

Dim RS

Dim i,j,k

Dim Excelconn

Dim Excelfile

Dim Objexcelapp

Dim Objexcelbook

Dim bgcolor

Xlsstr = ""

Execlfile = Server.MapPath (xlsfilename)

Set Objexcelapp = CreateObject ("Excel.Application")

Objexcelapp.quit

Set Objexcelapp = CreateObject ("Excel.Application")

Objexcelapp.quit

Objexcelapp.displayalerts = False ' does not show warning

ObjExcelApp.Application.Visible = False ' does not display interface

ObjExcelApp.WorkBooks.Open (Execlfile)

Set Objexcelbook = Objexcelapp.activeworkbook

ReDim Arrsheets (ObjExcelBook.Sheets.Count)

For I=1 to ObjExcelBook.Sheets.Count

Arrsheets (i) = Objexcelbook.sheets (i). Name

Next

Objexcelapp.quit

Set objexeclapp=nothing

'#################

' Power by www.knowsky.com

'#################

Set excelconn = Server.CreateObject ("ADODB. Connection ")

Exceldriver = "Driver={microsoft Excel Driver (*.xls)};D bq=" & Execlfile

Excelconn.open Exceldriver

Set rs = Server.CreateObject ("Adodb.recordset")

For i = 1 to UBound (arrsheets)

SQL = "SELECT * FROM [" & Arrsheets (i) & "$]"

' Show the names of each sheet

' Xlsstr = xlsstr & '

"& Arrsheets (i) &"

"

Xlsstr = Xlsstr & "

"

Rs. Open sql,excelconn,1,1

K = 1

While not rs.eof

If k Mod 2 <> 0 Then bgcolor = "bgcolor= #E0E0E0" Else bgcolor = ""

Xlsstr = xlsstr & ""

Xlsstr = xlsstr & ""

For j = 0 to Rs. Fields.count-1

Xlsstr = xlsstr & ""

Next

Xlsstr = xlsstr & ""

Rs.movenext

K = k + 1

Wend

Xlsstr = Xlsstr & "

"& RS (0) &" "& RS (j) &"

"

Rs. Close

Next

Excelconn.close

Set Excelconn = Nothing

Switchexcelinfo = Xlsstr

End Function

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.