Microsoft.Office.Interop中ASP.net的分析器错误

时间:2014-01-17 20:55:05

标签: asp.net excel

当我添加“项目/添加引用...”

Microsoft Excel 12.0对象库

Microsoft DAO 3.6对象库

Microsoft ActiveX数据对象6.1库

我收到“Excel,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null”的解析器错误 而不是版本12.0。

这是我的代码:

Imports Microsoft.Office.Interop
Imports System.Data.SqlClient

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    'From Excel
    Dim exlApp As Microsoft.Office.Interop.Excel.Application
    Dim exlWb As Microsoft.Office.Interop.Excel.Workbook
    Dim exlWs As Microsoft.Office.Interop.Excel.Worksheet
    Dim Arr(25, 25), j, k
    exlApp = CreateObject("Excel.Application")
    exlWb = exlApp.Workbooks.Open("C:\Users\path\file1.xlsm")
    exlWs = exlWb.Sheets("Sheet1")
    exlWb.Activate()
    For k = 1 To 10
        For j = 1 To 3
            Arr(j, k) = exlWs.Cells(j + 1, k + 2)
        Next j
    Next k
    exlWb.Close()
    exlWs = Nothing
    exlWb = Nothing
    exlApp.Quit()
    exlApp = Nothing
End Sub

错误代码:

Could not load type 'Microsoft.Office.Interop.Excel._Application' from assembly 'Excel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The type is marked as eligible for type equivalence, but the containing assembly is not loaded as fully trusted.

1 个答案:

答案 0 :(得分:0)

Microsoft Office Interop不支持与服务器端一起使用,例如ASP.NET。您需要找到替代解决方案。请参阅Microsoft的Considerations for server-side Automation of Office