RE: How to Write into Excel
From: Stan the Mouse (StantheMouse_at_discussions.microsoft.com)
Date: 10/31/04
- Previous message: nithin: "Re: Need connection code"
- In reply to: Stan the Mouse: "How to Write into Excel"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 30 Oct 2004 22:38:03 -0700
Sorry some chinese inside.
mode = LCASE(Request("mode"))
gif = Request("gif")
Set cnnExcel = Server.CreateObject("ADODB.Connection")
cnnExcel.Open "DBQ=" & Server.MapPath("counter.xls") & ";" &
"DRIVER={Microsoft Excel Driver (*.xls)}; ReadOnly=False; IMEX=2; Extended
Properties=Excel 8.0;"
SET rs = Server.CreateObject("ADODB.Recordset")
SET rshist = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM counter;", cnnExcel, 1,3
rshist.Open "SELECT * FROM counthist;", cnnExcel, 1,3
LASTIP = RS("LASTIP")
NEWIP = REQUEST.servervariables("REMOTE_ADDR")
IF CSTR(RS("DATE")) <> CSTR(DATE()) THEN ' 如果日期已過了一天
' RS("DATE") = DATE() ' 將日期改為今天
RS("Year") = Year(date)
RS("Month") = month(date)
RS("Day") = day(date)
RS("YESTERDAY") = RS("TODAY") ' 將今日人數與昨日人數交換
RS("TODAY") = 1 ' 重新計算今日登入人數
RS.update ' 儲存資料
END IF
IF LASTIP <> NEWIP THEN ' 比對 IP ,不使用灌水式
RS("TOTAL") = RS("TOTAL") + 1 ' 總數加一
RS("TODAY") = RS("TODAY") + 1 ' 重新計算今日登入人數
RS("LASTIP") = NEWIP ' 將新登入者的 IP 寫入
RS.update ' 儲存資料
END IF
RS.update
response.write "<font size=2 color=000099>瀏覽總數: </font>"
GCounter( RS("TOTAL") )
response.write "<font size=2 color=000099> 今日人數: </font>"
GCounter( RS("TODAY") )
response.write "<font size=2 color=000099> 昨日人數: </font>"
GCounter( RS("YESTERDAY") )
cnnExcel.CLOSE ' 關閉資料庫
Function GCounter( counter )
Dim S, i, G
S = CStr( counter ) ' 先將數值轉成字串 S
' 逐一取出字串 S 的每一個字元,然後串成 <IMG SRC=?.gif> 的圖形標示
For i = 1 to Len(S)
G = G & "<IMG SRC=./GIF1/" & Mid(S, i, 1) & ".gif Align=middle>"
Next
response.write G
End Function
"Stan the Mouse" wrote:
> I would like to use excel as a database to link up with
> my web site. is that feasible?
>
> it seems that when I replace the Access by Excel, there
> are always error messages regarding readonly or can not
> write into the excel file.
>
> can anyone help me, please?
>
> http://stanleychan.myftp.org/asp/counter1/test-gcount.asp
> http://stanleychan.myftp.org/asp/counter1/counter.xls
> The code
> http://stanleychan.myftp.org/asp/counter1/test-gcount.txt
>
> Many Many thanks
>
- Previous message: nithin: "Re: Need connection code"
- In reply to: Stan the Mouse: "How to Write into Excel"
- Messages sorted by: [ date ] [ thread ]