Click here to Skip to main content
15,896,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
 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.


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
VB
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)


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
Posted
Updated 5-May-16 0:48am

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900