Tech Off Thread

8 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

.NET Framework, Excel Object Library reference

Back to Forum: Tech Off
  • User profile image

    I am using the Microsoft .NET Framework SDK v1.1. I am trying to add a reference to the Microsfot Excel Object Library.

    Am I correct in assuming this is done by using the reference switch with csc? If it is possible to do with the framwork, what filename should I be passing?



  • User profile image

    Are you trying to message excel like the old COM days? If so I believe that you have to do so using com Interop ( because excel is still a COM application ). We have software in he field that does this every day.

    Here is a little snippet of code ripped from one of my test apps that plays with excel extensively. I have not added any references to excel in the references section. I am using Late binding which may or may not be appropriate for you setup. We use late binding because the application needs to be able to run in systems where excel is not installed.

    Formatting in this message editor is less than ideal but you should be able to get the point...
    Please no flames about the inherant issues in this code I know they are many Its only from one of my test rigs folks....

    Here goes

    Dim ex As Object

    Dim sh As Object

    Dim iRatingIndex As Integer

    For iRatingIndex = 0 To sCategories.GetUpperBound(0)

    Dim _workbook As Object


       ex = CreateObject("Excel.Application")

    Catch trouble As Exception

       MsgBox(trouble.Message, MsgBoxStyle.Exclamation,    "Houston... we have a problem")

    Exit Sub

    End Try

    ex.visible = True

    ex.ScreenUpdating = False

    ' create the 26 worksheets

    _workbook = ex.workbooks.add()

    While ex.activeworkbook.worksheets.count < 26


    End While

    Dim iIndex As Integer

    ' set the name of each worksheet

    For iIndex = 1 To 26

       ex.workbooks.item("Book1").worksheets(iIndex).name = Me._worksheets(iIndex).Name


  • User profile image

    I have been using the reference

    In instruction 3 it states you need to add a reference to the Microsoft Excel Object Library. As I do not currently own the IDE, I am coding via notepad.

    When I compile the program I get the message:

    excel.cs(3,25): error CS0234: The type or namespace name 'Office' does not exist in the class or namespace 'Microsoft' (are you missing an assembly reference?)

    Line 3 is:
    using Excel = Microsoft.Office.Interop.Excel;

    This is part of instruction 7 of the MSDN article.

  • User profile image

    Found an example which compiles fine within the SDK, just got to study it and work out how to apply it to my program.

  • User profile image

    Did you figure out that you need to create a COM interop assembly?

    Check out the .NET Framework Type Library to Assembly Converter: tlbimp.exe


  • User profile image

    You should try using the Office PIAs. More info about COM Interop.

  • User profile image

    Yeah, eventually figured out that was what was wrong.

    Going to get myself some books on C#, although will have to wait a bit, as had to buy some books for my physics course.

    Probably get Visual C#.NET Standard soon as well, but I'll start off with the evaluation copy of Visual Studio I have.

    Thanks for all the quick replies

  • User profile image

    Is there a reason why you need to create an Excel object?

    You can easily have your app output an Excel xml file.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.