开发机器为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("")
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位版。所以应该不是目录读写权限的问题。
查看系统日志,错误信息为: