none
Excel/Word files is not opened on client side using of microsoft.office.interop.excel component RRS feed

  • Question

  • Hi,

    I am used microsoft.office.interop.excel component for the opening of word and excel files.

    It's working fine on local host machine but after deployed on server machine. it's not opening on client machine.

    I am click from client machine but file opened on server machine.

    my sample code here:

    Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
    excelApp.Visible = true;
    Excel.Workbook newWorkbook = excelApp.Workbooks.Add();
    string workbookPath = path;
    Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
                                   0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
                                   true, false, 0, true, false, false);
    Excel.Sheets excelSheets = excelWorkbook.Worksheets;
    string currentSheet = "Sheet1";
    Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
    Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");

    Please solution

           

    Regards,

    Jayesh Prajapati

    • Moved by Sabah ShariqMVP Sunday, May 14, 2017 2:31 PM Moved from Visual C#
    Sunday, May 14, 2017 8:48 AM

All replies

  • The issue most likely is either permissions on the server (while you have permissions on local host) or Excel is not installed on the server.

    My guess this is a permission issue and if so you will need to set permissions in IIS logging in as an administrator. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, May 14, 2017 9:11 AM
  • Hi,

    I have done permission on server from DCOMCNFG.

    Before set permission,i found error like

    Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied.

    Now the case is file opening but on server machine. it need to open on client machine.

    Please advise.

    Sunday, May 14, 2017 9:53 AM
  • Hi,

    I have done permission on server from DCOMCNFG.

    Before set permission,i found error like

    Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied.

    Now the case is file opening but on server machine. it need to open on client machine.

    Please advise.

    My team does a lot with Excel in our web SPA web applications and found the best solution is to use Open Office XML which if never used before can take a while to learn but the up side is none of the issues you are having currently as there is no dependency on Introp.Excel.

    The next best option is to use a third party library, Spreadsheetlight but all the sample code is in C# yet easy enough to convert.

    Simple examples I've done for other forum post

    Imports SpreadsheetLight
    Imports DocumentFormat
    Public Class Form1
        ''' <summary>
        ''' Create a new Excel file, import DataTable then save to the new file
        ''' http://spreadsheetlight.com/downloads/SpreadsheetLight.chm
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn With {.ColumnName = "FirstName", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn With {.ColumnName = "LastName", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn With {.ColumnName = "BirthDay", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn With {.ColumnName = "Points", .DataType = GetType(Integer)})
    
            dt.Rows.Add(New Object() {"Karen", "Payne", "8/8/1960", 400})
            dt.Rows.Add(New Object() {"Anne", "Gallagher", "1/1/1961", 300})
            dt.Rows.Add(New Object() {"Mary", "Jones", "8/8/1990", 0})
    
            Using ops = New SLDocument()
                'http://spreadsheetlight.com/downloads/samplecode/HelloWorld.cs
    
                ops.AddWorksheet("People")
                ops.DeleteWorksheet("Sheet1")
    
                'ops.ImportDataTable("A1", dt, False)
    
                ops.SetCellValue("E1", "Modified on")
                ops.SetCellValue("F1", Now)
                Dim style As SLStyle = ops.CreateStyle()
                style.FormatCode = "MM/dd/yyyy"
                ops.SetCellStyle("F1", style)
    
                ops.SaveAs(IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DemoFileVb.xlsx"))
            End Using
        End Sub
        ''' <summary>
        ''' Open an existing file and insert from DataTable
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim fileName As String = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DemoFileVb.xlsx")
            If IO.File.Exists(fileName) Then
                Dim dt As New DataTable
                dt.Columns.Add(New DataColumn With {.ColumnName = "FirstName", .DataType = GetType(String)})
                dt.Columns.Add(New DataColumn With {.ColumnName = "LastName", .DataType = GetType(String)})
                dt.Columns.Add(New DataColumn With {.ColumnName = "BirthDay", .DataType = GetType(String)})
                dt.Columns.Add(New DataColumn With {.ColumnName = "Points", .DataType = GetType(Integer)})
    
                dt.Rows.Add(New Object() {"Karen", "Payne", "8/8/1960", 400})
                dt.Rows.Add(New Object() {"Anne", "Gallagher", "1/1/1961", 300})
                dt.Rows.Add(New Object() {"Mary", "Jones", "8/8/1990", 0})
    
                Using ops = New SLDocument(IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DemoFileVb.xlsx"))
                    ops.ImportDataTable("A1", dt, False)
                    ops.Save()
                End Using
            End If
        End Sub
    End Class
    
    
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, May 14, 2017 3:55 PM
  • Hello,

    Please visit Considerations for server-side Automation of Office

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    You could use Open XML library to manipulate Office files. Or you could try the third party library as Kareninstructor suggested.

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 15, 2017 3:06 AM
    Moderator