下面是我用ASP.NET开发的一个网站的代码片断,Private Declare Auto Function GetWindowThreadProcessId Lib "User32" (ByVal hWnd As Integer, ByRef intProcessID As Integer) As IntegerPrivate Sub SendExcel(ByVal dt As DataTable)
Dim oExcelApp As Excel.Application = Nothing
Dim oExcelBook As Excel.Workbook = Nothing
Try
操作EXCEL文件……
Finally
If Not oExcelApp Is Nothing Then
Dim intProcessId As Integer = 0
Dim intThreadId As Integer = 0
Try
If Not oExcelBook Is Nothing Then
oExcelBook.Close()
oExcelBook = Nothing
End If
oExcelApp.Workbooks.Close()
oExcelApp.Quit()
If oExcelApp.VBE.MainWindow.HWnd <> 0 Then
intThreadId = GetWindowThreadProcessId(oExcelApp.VBE.MainWindow.HWnd, intProcessId)
End If
Catch ex As Exception
Finally
oExcelApp = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
If intProcessId <> 0 Then
System.Diagnostics.Process.GetProcessById(intProcessId).Kill()
End If
End If
End Try
发送EXCEL文件内容……
End Sub不知为什么GetWindowThreadProcessId函数返回的intProcessId和intThreadId总是0,我用C++和VB.NET编了两个小程序在同一时刻用相同的值试验都没问题。我猜可能是ASP.NET的用户和权限设置问题,也不知对不对,具体怎样设置就更不清楚了。没办法,只好请高手指教。顺便,当时因为EXCEL对象无法建立,我手工往web.config文件里加过<identity impersonate="true"/>这么一句。
Dim oExcelApp As Excel.Application = Nothing
Dim oExcelBook As Excel.Workbook = Nothing
Try
操作EXCEL文件……
Finally
If Not oExcelApp Is Nothing Then
Dim intProcessId As Integer = 0
Dim intThreadId As Integer = 0
Try
If Not oExcelBook Is Nothing Then
oExcelBook.Close()
oExcelBook = Nothing
End If
oExcelApp.Workbooks.Close()
oExcelApp.Quit()
If oExcelApp.VBE.MainWindow.HWnd <> 0 Then
intThreadId = GetWindowThreadProcessId(oExcelApp.VBE.MainWindow.HWnd, intProcessId)
End If
Catch ex As Exception
Finally
oExcelApp = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
If intProcessId <> 0 Then
System.Diagnostics.Process.GetProcessById(intProcessId).Kill()
End If
End If
End Try
发送EXCEL文件内容……
End Sub不知为什么GetWindowThreadProcessId函数返回的intProcessId和intThreadId总是0,我用C++和VB.NET编了两个小程序在同一时刻用相同的值试验都没问题。我猜可能是ASP.NET的用户和权限设置问题,也不知对不对,具体怎样设置就更不清楚了。没办法,只好请高手指教。顺便,当时因为EXCEL对象无法建立,我手工往web.config文件里加过<identity impersonate="true"/>这么一句。
解决方案 »
- 哪位大哥发个DBHelper(用IDBConnection接口的也好)或全点的SQLHelper给我,谢谢!
- 谁有汉字转换拼音的完美解决方案啊?要求能解决多音字问题
- asp.net不用runat=server的file控件,就用html的file控件.能不能上传文件啊?????
- 请教ClickOnce发布问题!
- 请问:Dropdownlist在动态生成了一些项时,好像用selectindex不能表示所选择的项。如何解决
- 新手问题:如何根据datalist中的子控件的值,控制另一个子控件的visible属性
- 使用<asp:ButtonColumn runat="server"/>时,怎么定位到锚点
- 网页过期问题!
- 静态html转aspx求助
- 谁来帮我写个asp.net读取.htm文件的ubb
- 在通过增加一条记录后,怎样在dataGrid中让这条新增记录被选中,希望有好的方法
- 4G的内存,如何配置iis6的应用程序池?
asp.net中使用这样的调用是有一些问题的我想问一下,你的excelapplication是否可以成功建立??另外,你可以试试不在web应用中建立excelapplication,直接专门为这个做一个工程,这样的话,可以尽量的避免权限的问题,在aspnet的页面中直接操作这个就可以了