dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: .NET 2.0 and Excel

  1. #1
    Join Date
    Dec 2010
    Posts
    2

    .NET 2.0 and Excel

    We are using .NET2.0 and Office 2003 to develop a desktop application. We met the following problem which may fail the project.

    We developed some functions in our .NET application and exposed to Excel as an external automation. Then we developed reports template in Excel with these custom functions to generate our report data defined in Excel cells. However, when we tried to refresh the report via .NET to call Excel in background mode, we met the problem that the defined automation is either not loaded or not working after loading. It is extremely volatile. Then we could not refresh the data as desired to display it in .NET forms.

    Anyone met the same problem before? Is there a solution or workaround for this? Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: .NET 2.0 and Excel

    Maybe. Depends on what your code looks like. Please use TAGS
    Code:
    ' Like This
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Dec 2010
    Posts
    2

    Re: .NET 2.0 and Excel

    When we tried to recaculate the workbook, sometimes it works and sometimes not.



    Public Sub ReCalculateWorkBook(ByVal FilePath As String)





    Dim wb As Workbook

    wb = OpenBook(FilePath)



    Try

    'ExcelApp.Visible = True

    _excelApp.AddIns("JmsExcelFunction").Installed = False

    _excelApp.AddIns("JmsExcelFunction").Installed = True

    'If IsError(ExcelApp.Evaluate("=TestRun()")) Then

    ' _excelApp.AddIns("JmsExcelFunction").Installed = False

    ' _excelApp.AddIns("JmsExcelFunction").Installed = True

    'End If

    'If IsError(ExcelApp.Evaluate("=TestConnection()")) Then

    ' _excelApp.AddIns("JmsExcelFunction").Installed = False

    ' _excelApp.AddIns("JmsExcelFunction").Installed = True

    'End If



    ExcelApp.CalculateFullRebuild()

    'ExcelApp.Visible = False

    Catch ex As Exception

    Task.SendInformationToUI(New UITextChangedEventArgs("", "Error." + ex.Message))

    End Try

    Task.SendInformationToUI(New UITextChangedEventArgs("", "Finished."))

    wb.Close(True)

    System.Runtime.InteropServices.Marshal.ReleaseComObject(wb)

    End Sub

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: .NET 2.0 and Excel

    Add CODE TAGS. Quote this to see how!
    Code:
    ' THIS IS CODE INSIDE OF CODE TAGS
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)