Use of Excel Interop within C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=

    Use of Excel Interop within C#

    I've been tasked to translate a C# program to VB. (Dot Net 2.0.)

    I'm starting from scratch with no documentation and I'm trying to understand
    what the original programmer did. (The 'original programmer' is conveniently
    off on vacation so I can't ask him.) The program deals in some way with Excel
    spreadsheets. There is a line of code in the program:

    CurSheet =
    (Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

    where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.

    What I don't understand is that get_Item call. It leads to something
    labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
    apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
    file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.

    I have no idea how or why this file was generated. Has anyone else out
    there ever seen anything like this? What techniques are being used here?

  • cfps.Christian

    #2
    Re: Use of Excel Interop within C#

    From the looks of it he's getting the current sheet off of the file in
    that directory (something like the default sheet).
    If he's not getting the default sheet then it looks like he's getting
    a reference to a sheet. Unfortunately the Excel interop class was
    really designed for VB so I coded all my excel processes into a VB.NET
    dll and accessed it from C#. This means that the constructors have
    like 15 elements and in VB they're optional.

    Comment

    • Hans Kesting

      #3
      Re: Use of Excel Interop within C#

      B. Chernick used his keyboard to write :
      I've been tasked to translate a C# program to VB. (Dot Net 2.0.)
      >
      I'm starting from scratch with no documentation and I'm trying to understand
      what the original programmer did. (The 'original programmer' is conveniently
      off on vacation so I can't ask him.) The program deals in some way with Excel
      spreadsheets. There is a line of code in the program:
      >
      CurSheet =
      (Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );
      >
      where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.
      >
      What I don't understand is that get_Item call. It leads to something
      labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
      apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
      file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.
      >
      I have no idea how or why this file was generated. Has anyone else out
      there ever seen anything like this? What techniques are being used here?
      Just looking at the words in the code (and having seen Excel) it seems
      that a particular worksheet is selected from the entire workbook, based
      on some "driverName ". This selected worksheet is assinged to the
      variable CurSheet.

      I'm guessing that a "correcter" C# syntax would be
      CurSheet =
      (Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets[driverName];

      This (the [] instead of a call to Item) is regular C# to get a specific
      item from some list. I just don't know if that still holds with
      "interop" calls.

      Hans Kesting


      Comment

      • sloan

        #4
        Re: Use of Excel Interop within C#

        If all you're doing is reading data from excel (which will greatly simplify
        your life), then abandon the interop.

        google something like this

        Excel LoadDataSet "select * from [Sheet1$]"

        Or you can go here:
        http://sholliday.space s.live.com/blog/cns!A68482B9628 A842A!176.entry
        and find the code in there (somewhere). Code is downloadable.


        If the developer is coming back, then wait for him to come back. That
        excel interop crap is tricky.
        Too tricky.





        "B. Chernick" <BChernick@disc ussions.microso ft.comwrote in message
        news:D15E8AEE-02DC-4A3D-9567-D7FBA5284BE0@mi crosoft.com...
        I've been tasked to translate a C# program to VB. (Dot Net 2.0.)
        >
        I'm starting from scratch with no documentation and I'm trying to
        understand
        what the original programmer did. (The 'original programmer' is
        conveniently
        off on vacation so I can't ask him.) The program deals in some way with
        Excel
        spreadsheets. There is a line of code in the program:
        >
        CurSheet =
        (Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );
        >
        where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.
        >
        What I don't understand is that get_Item call. It leads to something
        labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
        apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
        file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.
        >
        I have no idea how or why this file was generated. Has anyone else out
        there ever seen anything like this? What techniques are being used here?
        >

        Comment

        • =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=

          #5
          Re: Use of Excel Interop within C#

          I'm not absolutely sure I understand your response. However I've found
          something that might make things simpler. That file in the temp directory is
          definitely 'temp'. It only appears when I do a 'Go To Definition' and
          vanishes when I close the project. I've also checked the project properties
          to make sure there aren't any exotic references or declarations. (Looks
          fairly standard. As far as I can tell the C# and VB project properties are
          identical.)

          Given that, my only mystery (I think) is why the C# line

          CurSheet =
          (Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

          does not want to translate into VB, given that both projects have the same
          reference to the interop and both use the same declared variables?

          Still trying. I get the feeling I'm missing something simple.

          "cfps.Christian " wrote:
          From the looks of it he's getting the current sheet off of the file in
          that directory (something like the default sheet).
          If he's not getting the default sheet then it looks like he's getting
          a reference to a sheet. Unfortunately the Excel interop class was
          really designed for VB so I coded all my excel processes into a VB.NET
          dll and accessed it from C#. This means that the constructors have
          like 15 elements and in VB they're optional.
          >

          Comment

          • =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=

            #6
            Re: Use of Excel Interop within C#

            That's probably the solution. When I changed the C# to WorkSheet[driverName]
            and ran it through the translator, I got this:

            CurSheet = DirectCast(WB.W orksheets.Item( driverName),
            Microsoft.Offic e.Interop.Excel .Worksheet)

            No apparent errors.

            (The programmer has admited that the original code is not a finished product.)

            Thanks.

            "Hans Kesting" wrote:
            B. Chernick used his keyboard to write :
            I've been tasked to translate a C# program to VB. (Dot Net 2.0.)

            I'm starting from scratch with no documentation and I'm trying to understand
            what the original programmer did. (The 'original programmer' is conveniently
            off on vacation so I can't ask him.) The program deals in some way with Excel
            spreadsheets. There is a line of code in the program:

            CurSheet =
            (Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets.get_ Item(driverName );

            where CurSheet is 'Microsoft.Offi ce.Interop.Exce l.Worksheet '.

            What I don't understand is that get_Item call. It leads to something
            labeled (in the VS tab) as 'Sheets [from metadata]' which in turn is
            apparently a file within directory 'c:\temp\5232$E xcel.dll$v1.1.4 322. The
            file name itself is Microsoft.Offic e.Interop.Excel .Sheets.cs.

            I have no idea how or why this file was generated. Has anyone else out
            there ever seen anything like this? What techniques are being used here?
            >
            Just looking at the words in the code (and having seen Excel) it seems
            that a particular worksheet is selected from the entire workbook, based
            on some "driverName ". This selected worksheet is assinged to the
            variable CurSheet.
            >
            I'm guessing that a "correcter" C# syntax would be
            CurSheet =
            (Microsoft.Offi ce.Interop.Exce l.Worksheet)WB. Worksheets[driverName];
            >
            This (the [] instead of a call to Item) is regular C# to get a specific
            item from some list. I just don't know if that still holds with
            "interop" calls.
            >
            Hans Kesting
            >
            >
            >

            Comment

            Working...