如何解决无法在没有安装msoffice的情况下在服务器机器上加载excel组装问题? [英] How to solve could not load excel assembly problem on server machine without install msoffice ?

查看:152
本文介绍了如何解决无法在没有安装msoffice的情况下在服务器机器上加载excel组装问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发一个网站,因为我将使用excel.interop.dll在开发机器安装的ms office 2013中将值从数据表导出到excel文件,所以它可以工作,但是当我部署时在没有ms office或excel.interop.dll的服务器机器中,所以它显示如下错误



Hi I am developing one website,in that i will export values from data table to excel file,using excel.interop.dll,in developing machine installed ms office 2013, so it works,but when i deploy in server machine which is not have ms office or excel.interop.dll ,so it show error like this

 Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.





如何解决这个问题而不在主服务器上安装ms office,主服务器永远不允许安装任何软件,所以不建议我安装ms office,单独的dll可以安装,如果可能的话怎么样?





这是我的代码



How to solve this problem without installing ms office in main server,main server never allowed to install any software,so dont suggest me to install ms office,separate dll can install,if possible then how ?


This is my code

Imports Microsoft.Office.Interop

  Dim sqlcon As New SqlConnection(ConfigurationManager.ConnectionStrings("CS").ToString())
            Dim objDataAdapter As New SqlDataAdapter(ExcQuery, sqlcon)
            Dim objDataTable As New DataTable
            objDataAdapter.Fill(objDataTable)

            dynamicFLXname = Date.Now.ToString("ddMMMyyyyhhmmss", System.Globalization.CultureInfo.InvariantCulture)
            dynamicFLXname = dynamicFLXname + ".xlsx"
            Dim strFileName As String = Server.MapPath(".") + "\Temp\" + dynamicFLXname

            If objDataTable.Rows.Count = 0 Then
                manager.Alert("No Result !")
                Exit Sub
            End If


            If objDataTable.Rows.Count > 0 Then
                Dim _excel As New Excel.Application
                Dim wBook As Excel.Workbook
                Dim wSheet As Excel.Worksheet
                wBook = _excel.Workbooks.Add()
                wSheet = wBook.ActiveSheet()
                Dim dt As System.Data.DataTable = objDataTable
                Dim dc As System.Data.DataColumn
                Dim dr As System.Data.DataRow
                Dim colIndex As Integer = 0
                Dim rowIndex As Integer = 0
                ' If CheckBox1.Checked Then
                For Each dc In dt.Columns
                    colIndex = colIndex + 1
                    wSheet.Cells(1, colIndex) = dc.ColumnName
                Next
                '  End If
                For Each dr In dt.Rows
                    rowIndex = rowIndex + 1
                    colIndex = 0
                    For Each dc In dt.Columns
                        colIndex = colIndex + 1
                        wSheet.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
                    Next
                Next
                wSheet.Columns.AutoFit()
                wBook.SaveAs(strFileName)

                ''  ReleaseObject(wSheet)
                wBook.Close(False)
                ''  ReleaseObject(wBook)
                _excel.Quit()
                '' ReleaseObject(_excel)





我尝试了什么:



我试着直接推荐excel dll,不工作,我试着推荐ms office对象15.0对象库,永远不会工作。



问候

Aravind



What I have tried:

I am try to refer excel dll directly,not work,i try to refer ms office object 15.0 object library ,never work.

Regards
Aravind

推荐答案

您的代码正在做的是自动化Excel,因此您需要安装Excel才能工作。不支持从asp.net自动化Excel,它不会起作用,并且您的代码中可能还有很多其他东西在网站未在本地运行时无法正常工作。



您需要使用与asp.net兼容的技术,例如aspose,或Excel ODBC驱动程序,Open XML SDK等。
What your code is doing is automating Excel, so you need Excel installed to work. Automating Excel from asp.net isn't supported and it isn't going to work and you probably have lots of other things in your code that aren't going to work when the site isn't running locally.

You need to use technology that is asp.net compatible such as aspose, or the Excel ODBC driver, Open XML SDK and so on.


这篇关于如何解决无法在没有安装msoffice的情况下在服务器机器上加载excel组装问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆