<%
Rem Initialization excelapplication Working environment
Dim Excelapp,ebook,esheet
Set excelapp = CreateObject ("Excel.Application") ' establishes an Excel object
Excelapp.displayalerts=false ' does not show warning
Excelapp.application.visible=false ' does not display interface
Rem initialization of Excel data
' ExcelApp.Workbooks.Open (Server.MapPath ("Zzz.xls")) ' opens the Excel work book, which replaces the following line
Set ebook=excelapp.workbooks.add ' new Excel work Ben
Set ebook=excelapp.workbooks (1) ' references the first working book
Set esheet = ebook.worksheets (1) ' References first worksheet
Rem Data Import
Dim i,img
i = 1
For I=1 to 5
Esheet.cells (i,1). value= "Field One" &i
Esheet.cells (i,2). value= "Field two" &i
Esheet.cells (i,3). value= "Field three" &i
Esheet.cells (i,4). Select ' Selects cell 4th cells in row I
Set Img=esheet.pictures.insert (Server.MapPath ("people.jpg")) ' Inserts a picture in the above position and gets a reference to the picture
Img. Top=img. Top+2 ' Adjusts the picture position, the same below, otherwise it will press the table sideline
Img. Left=img. Left+2 ' units are pounds
Esheet.rows (i). Rowheight=img. Height+4 ' Adjusts the height of the current line so that it automatically is the same height as the picture
Next
Rem preservation of the work done above
' Ebook.save ' If you are opening an existing Excel file, you can use this line instead of the following line
Ebook.saveas Server.MapPath ("Zzz.xls")
Set esheet=nothing
Set ebook=nothing
' Excelapp.quit ' must exit, otherwise Excel's process stays in the operating system.
Set excelapp = Nothing
%>
<%
Dim Conn,rs,sql
Sub dbopen ()
Dim Db:db=server.mappath ("Zzz.xls")
Set conn=server.createobject ("Adodb.connection")
On Error Resume Next
Conn. Open "Provider=Microsoft.Jet.OLEDB.4.0; Extended properties= "" Excel 8.0; Hdr=yes ";D ata source=" & DB
Rem HDR defaults to Yes, which means the first row is the field name, otherwise it is considered content
Rem for Excel2007, but should be: "provider=microsoft.ace.oledb.12.0; Extended properties=excel 12.0;data source=xxx.xlsx; "
If Err.number<>0 Then
Err.Clear
Response.Write ("Response.End ()
End If
On Error GoTo 0
End Sub
Sub dbclose ()
IF Isnotblank (conn) Then
Conn. Close ()
Set conn=nothing
End If
End Sub
Function Isnotblank (ByRef TempVar)
IsBlank = True
Select case VarType (TempVar)
Case 0,1 ' Empty & Null
IsBlank = False
Case 9 ' Object
If TypeName (TempVar) = "Nothing" Or TypeName (TempVar) = "Empty" Then
IsBlank = False
End If
End Select
End Function
Call Dbopen ()
Sql= "SELECT * from [sheet1$]" "Note the table name, you need to add a symbol after the sheet name $
Set Rs=conn. Execute (SQL)
While not Rs. Eof
Response.Write (RS (0) & ",")
Response.Write (RS (1) & ",")
Response.Write (RS (2) & "<br/>" &vbcrlf)
Rs. Movenext
Wend
Rs. Close:set rs=nothing
Call Dbclose ()
%>