'--- 導出Excel 報表時, 會出現 Excel 進程無法 殺掉的情況;
應 將輸出報表的部分代碼寫成一個 類;
實際執行時, 將產生的 dataSet 傳給 這個 類;
(在這個類中, 包含 了 excel 進程的注銷代碼)
執行結束後,
再將這個類注銷一次;
即可;
'--------------------
If Not Page.IsPostBack Then
'2006-08-14 Added
' 防止非法登入
If Context.User.Identity.Name = Nothing Then
Response.Write("<script defer>alert('Session 已過期 或 非法登入! 請重新登入')</script")
Exit Sub
End If
End If
'--------------------
#Region "清除產生的歷史報表"
Private Sub clearHistoryReport(ByVal path As String, ByVal kzm As String)
Dim intx As Integer
Dim aa As String
Dim str() As String
' path = path + "/rpt"
str = Directory.GetFiles(path, kzm)
' directory.GetFiles("",
For intx = 0 To str.Length - 1
aa = Directory.GetCreationTime(str(intx))
aa.Substring(0, 10)
If aa.Substring(0, 10) <> System.DateTime.Today.ToString().Substring(0, 10).ToString Then
File.Delete(str(intx))
End If
Next
End Sub
'Function del(ByVal path As String, ByVal kzm As String)
' Dim intx As Integer
' Dim aa As String
' Dim str() As String
' path = path + "/Template"
' str = Directory.GetFiles(path, kzm)
' For intx = 0 To str.Length - 1
' aa = Directory.GetCreationTime(str(intx))
' aa.Substring(0, 10)
' If aa.Substring(0, 10) <> System.DateTime.Today.ToString().Substring(0, 10).ToString Then
' File.Delete(str(intx))
' End If
' Next
'End Function
#End Region
'-----------------------------------------------------------------------------------
'--將已編碼(server.htmlEncode)的 數據, 解碼後 賦值給其它變量;
'--經過測試, 建議2 次使用 HtmlDecode , 否則 仍將會有 不期望的字符出現。
oCells(rowbegin+1+1,7)
= server.htmlDecode(server.htmlDecode(myds.table(0).Rows(i).Item("memo")))
'--- 將文件讀取後, 顯示在 客戶端;
If System.IO.File.Exists(Server.MapPath("~") + "/rpt/" + fileOut) Then
Response.Write("<script language=javascript>window.open('rpt/" + fileOut + "','report','top=15,left=15,width=800,height=500,scrollbars=yes,resizable=yes,status=yes,toolbar=true,menubar=yes')</script>")
End If
'---不能打開 server 端的 excel 的問題解決了。
原來 是 page_load 裡的一句話 導致的, 把它刪除就可以了。
page.smartNavigation = true
可使用下面方法替代:
<body
οnscrοll="document.Form1.txtScrollTop.value = document.body.scrollTop;" οnlοad="javascript:document.body.scrollTop=document.getElementById('txtScrollTop').value;"
>
<INPUT id="txtScrollTop" type="hidden" size="1" runat="server">