解决64位windows server 2008上调用Excel组件出现0x800A03EC错误

来源:互联网 发布:淘宝上哪家店铺包包好 编辑:程序博客网 时间:2024/06/03 18:09

开发机器为windows server 2003,安装了office 2003,从.aspx文件中调用excel处理xls文件。下面是部分代码:

Try        oExcel = New Microsoft.Office.Interop.Excel.Application        oExcel.DisplayAlerts = False        oExcel.Visible = False        tmpVersion = oExcel.Version                oExcel.Workbooks.Open(tmpDesFile)        oWorkbook = oExcel.Workbooks(1) '1 is Workbook1        oWorksheet = oWorkbook.Worksheets(1) '1 is Sheet1                tmpRange = oWorksheet.Cells.Range(oWorksheet.Cells(1, 1), oWorksheet.Cells(1, tmpColCount))        tmpAry = tmpRange.Value2        For rId = LBound(tmpAry, 1) To UBound(tmpAry, 1)            For fId = LBound(tmpAry, 2) To UBound(tmpAry, 2)                tmpValue = tmpAry(rId, fId)                Response.Write(tmpValue & "|")            Next            Response.Write("<br/>")        Next                        oWorkbook.Close(False)    Catch ex As Exception        tmpResult = "Error: " & ex.ToString() 'Error: has error, return error description    Finally        oWorksheet = Nothing        oWorkbook = Nothing        If Not IsNothing(oExcel) Then            oExcel.Quit()        End If        oExcel = Nothing        GC.Collect()        GC.WaitForPendingFinalizers() 'Wait excel real quit    End Try

确认无问题后上传到服务器,运行后却报错:

System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad) at ASP.test1_aspx.TestExcel() in C:\Test\site\Test1.aspx:line 53

计算机-默认 权限设置并未从地址 LocalHost(使用 LRPC) 使用 CLSID {000C101C-0000-0000-C000-000000000046} 和 APPID {000C101C-0000-0000-C000-000000000046} 向用户 IIS APPPOOL\Test SID (S-1-5-82-2448291975-4234089047-1793108301-2903605371-3779044736)授予对 COM 服务器应用程序的 本地 激活 权限。此安全权限可以使用组件服务管理工具进行修改。

查询注册表后发现CLSID:000C101C-0000-0000-C000-000000000046是一个服务,服务名称是MSIServer,显示名称是Windows Installer.

打开组件服务,准备修改MSIServer的激活权限,确发现所有字段都是只读的。此组件在32位版windows server上字段是可读写的。此路不通。

后经过反复摸索,发现这是Office 2003的一个Bug。

解决方法如下:

配置好相关目录的读写权限与组件服务管理工具中Excel的相关权限后,需要建立如下目录:

C:\Windows\SysWOW64\config\systemprofile\Desktop。

自此,问题解决。


原创粉丝点击