解决64位windows server 2008上调用objExcel.Workbooks.Open(xlsFile)出现Exception from HRESULT: 0x800A03EC错误

开发机器为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

服务器上office配置和权限配置与开发机器一样,除了os是windows server 2008 64位版。所以应该不是目录读写权限的问题。

查看系统日志,错误信息为:

计算机-默认 权限设置并未从地址 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 和 C:\Windows\SysWOW64\config\systemprofile\Desktop。

自此,问题解决。

posted on 2012-07-28 02:06  dk163  阅读(3118)  评论(1编辑  收藏  举报

导航