江湖告急:asp.net服务器端关闭EXCEKL进程问题!(参照多个帖子方法,仍不能解决,请大虾帮忙)
环境:WIN2003SERVER ASP.NET OFFICE2003 VB.NET2005
网络用户具用变更和写入文件权限
代码如下:
Private Sub psWriteToExcel(ByVal dtdata As DataTable)
Dim strPath As String
Dim strFileName As String
Dim objFile As Scripting.FileSystemObject
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim i As Integer
Try
strPath = Me.Server.MapPath( ".. ") & "\XlsModule\ "
strPathName = Dir(strPath, vbDirectory)
If strPathName = " " Then
MkDir(strPath)
End If
objFile = New Scripting.FileSystemObject
xlApp = CreateObject( "Excel.Application ")
xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets(1)
'EXCEL操作(略)
xlBook.SaveAs(strPath & strFileName)
xlBook.Close()
xlApp.Workbooks.Close()
xlApp.Quit()
ReleaseComObject(xlSheet)
ReleaseComObject(xlBook)
ReleaseComObject(xlApp)
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing
objFile = Nothing
Catch ex As Exception
Throw ex
End Try
End Sub
并在调用此函数后显示调用GC.Collect()
参考了多篇帖子:
方案1:
在服务器端检索Excel进程并KIll掉(用时间段查询,尽量避免误杀),可以实现,但是需要给用户Administrator权限,不安全,并且可能会杀死正常的进程,客户不会同意,不准备采用
方案2:
关闭所有引用Excel对象(app,workbook等,)
xlBook.Close()
xlApp.Workbooks.Close()
xlApp.Quit()
ReleaseComObject(xlSheet)
ReleaseComObject(xlBook)
ReleaseComObject(xlApp)
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing
并在调用Excel操作并在函数外(Excel工作区域外)显示调用GC.Collect(),未成功
方案3:
在创建Excel对象前判断是否有进程存在,有的话引用,没有再新建,保证只有一个进程,未成功。(本地好使,在服务器上仍每次新建一个进程)
Try
xlApp = Microsoft.VisualBasic.Interaction.GetObject(Nothing, "Excel.Application ")
Catch
xlApp = New Microsoft.Office.Interop.Excel.Application()
End Try
错误出在哪里呢,请各位多多帮忙。谁的回答解决问题就结帖给全部分,分不够再加。
[解决办法]
不懂,还是VB的,up
[解决办法]
帮顶
[解决办法]
老弟,还是在服务端结束进程吧(做个定时扫描程序)!客户端没那个权限!我也遇到了相同的问题