ASP read data EXCEL2

   
 


 

 

Home

Board-Forum-Diary

Administrator

ASP

=> ASP?

=> ASP : Connection Object

=> Connect DB access

=> Connect DB Ms Sql Server 7.0

=> ASP and SQL

=> ASP Mysql (ODBC)

=> ASP export Excel

=> ASP export Graph

=> ASP MS-word

=> ASP read data EXCEL

=> ASP read data EXCEL2

Business Manage

Computer Basic

Computer Hardware

Computer Software

Computer Tip

Computer Virus

Contact

Database

Firefox

Gallery

Game

HI5 ME!

Link

Project Demo

System Analysis

Website

Food & Drink

SkyDrive

MS-word

MS-excel

Mobile

Drug

Clock

Car & Motorcycle

Download

 


     
 

การอ่านข้อมูลจาก Microsoft Excel โดยแสดงผ่าน Web Site

Sample1.asp

<%@ LANGUAGE = VBScript %>
<% Option Explicit %>
<%
Const CDATABASE = "database.xls"
Dim oConn
Dim oRs
Dim Index
Dim sColorcount, sColorstyle
Dim sTemp

Sub Readdb()
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Excel 8.0;DATABASE=" & Server.MapPath(CDATABASE)
Set oRs = oConn.Execute("SELECT * FROM tabelle")


' -- XML Header
sTemp = "<html xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:x=""urn:schemas-microsoft-com:office:excel"" xmlns=""http://www.w3.org/TR/REC-html40"">" & vbcrlf
sTemp = sTemp & "<head><style>td.marked {background-color: rgb(196,196,196);}</style></head><body><xml><x:ExcelWorkbook></xml>" & vbcrlf

' -- Tabellenkopf
sTemp = sTemp & "<table cellspacing=""0"" cellpadding=""2"">" & vbcrlf
sTemp = sTemp & "<tr>" & vbcrlf
For Index=0 to (oRs.fields.count-1)
sTemp = sTemp & "<th><b>" & oRs(Index).Name & "</b></th>" & vbcrlf
Next
sTemp = sTemp & "</tr>" & vbcrlf

sColorcount = 1

' -- Tabelle
Do while (Not oRs.eof)
sTemp = sTemp & "<tr>" & vbcrlf
if (sColorcount and 1) = 0 Then sColorstyle = " class=""marked""" Else sColorstyle = ""
For Index=0 to (oRs.fields.count-1)
' sTemp = sTemp & "<td" & sColorstyle & ">" & myNumFormat(oRs(Index)) & "</td>" & vbcrlf
sTemp = sTemp & "<td" & sColorstyle & ">" & oRs(Index) & "</td>" & vbcrlf
Next
sTemp = sTemp & "</tr>" & vbcrlf
oRs.MoveNext
sColorcount = sColorcount + 1
Loop

' -- Tabellenende und Ende Ausgabe
sTemp = sTemp & "</table></body></html>" & vbcrlf

oRs.close
oConn.close
Response.write Server.HTMLEncode(sTemp)

End Sub

' -----------------------------------------------
' Hilfsfunktionen
' -----------------------------------------------

Function myNumFormat(sString)
'Const vbEmpty = 0
'Const vbNull = 1
'Const vbInteger = 2
'Const vbLong = 3
'Const vbSingle = 4
'Const vbDouble = 5
'Const vbCurrency = 6
'Const vbDate = 7
'Const vbString = 8

Select Case VarType(sString)
Case vbEmpty, vbNull
myNumFormat = "&nbsp;"
Case vbInteger, vbLong, vbSingle, vbDouble
myNumFormat = FormatNumber(sString, 2)
Case vbCurrency
myNumFormat = FormatCurrency(sString, 2)
Case vbDate
myNumFormat = FormatDateTime(sString, 0)
Case Else
myNumFormat = sString
End Select
End Function

%>
<html>
<head>
<title>Excel Active X </title>
<link rel="stylesheet" type="text/css" href="Include/stylesheet.css">
</head>
<body>
<b>Excel Active X</b>
<hr size="1" color="#000000">
<object id="Mappe" codebase="file:msowc.cab"
classid="CLSID:0002E510-0000-0000-C000-000000000046">
<param name=DisplayTitleBar value=true>
<param name=DataType value=HTMLData>
<param name=HTMLData value="<% call Readdb %>">
<p>Um diese Webseite interaktiv zu benutzen, m?ssen die Microsoft Office Web Components auf Ihrem Rechner installiert sein</p>
</object>
</body>
</html>

 

 






 
 

Total, there have been 126177 visitors (306631 hits) on this page!