Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Excel 2003 interop

Excel 2003 interop

Scheduled Pinned Locked Moved C#
csharpcomvisual-studiohelplearning
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dimitris Iliopoulos
    wrote on last edited by
    #1

    I am trying to write some data to excel 2003 from C#. I installed windows xp on a machine,visual studio.net and office 2003 from scratch to be sure everything is ok. I also install of course .NET programmability support for the office I write in C#: Excel.Application app = new Excel.Application(); app.visible=true; app.Workbooks.Open("c:/data.xls", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value) when i run it the first two lines work good and when it goes to the Open function a COMException come up telling me "old format or invalid type library", i also tried _Open function but the same thing happened. If i use an event in the Application object everything works fine,it crashes only when i go to the Workbooks property. PLEASE HELP From Greece: Dimitris Iliopoulos dimilio@yahoo.com

    H 1 Reply Last reply
    0
    • D Dimitris Iliopoulos

      I am trying to write some data to excel 2003 from C#. I installed windows xp on a machine,visual studio.net and office 2003 from scratch to be sure everything is ok. I also install of course .NET programmability support for the office I write in C#: Excel.Application app = new Excel.Application(); app.visible=true; app.Workbooks.Open("c:/data.xls", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value) when i run it the first two lines work good and when it goes to the Open function a COMException come up telling me "old format or invalid type library", i also tried _Open function but the same thing happened. If i use an event in the Application object everything works fine,it crashes only when i go to the Workbooks property. PLEASE HELP From Greece: Dimitris Iliopoulos dimilio@yahoo.com

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Did you add an assembly reference to the Office interop assemblies, or use the COM tab to add them? You should do the former. Unfortunately, they're not easy to get at. You must use the command prompt to copy them out of the respective directories in %WINDIR%\assembly\gac (you can't browse to it using Windows Explorer). If you downloaded the PIAs (Primary Interop Assemblies) from MSDN, then you have version 10 (Office XP). If you add a COM reference, then the interop assemblies in the GAC are not used during runtime, but the interop assemblies you generated. This is a pain, I know, but necessary. Microsoft only installs the Office 2003 assemblies into the GAC and doesn't make them easily accessible for development unless you use the Office project templates in VS.NET 2003.

      Microsoft MVP, Visual C# My Articles

      D 1 Reply Last reply
      0
      • H Heath Stewart

        Did you add an assembly reference to the Office interop assemblies, or use the COM tab to add them? You should do the former. Unfortunately, they're not easy to get at. You must use the command prompt to copy them out of the respective directories in %WINDIR%\assembly\gac (you can't browse to it using Windows Explorer). If you downloaded the PIAs (Primary Interop Assemblies) from MSDN, then you have version 10 (Office XP). If you add a COM reference, then the interop assemblies in the GAC are not used during runtime, but the interop assemblies you generated. This is a pain, I know, but necessary. Microsoft only installs the Office 2003 assemblies into the GAC and doesn't make them easily accessible for development unless you use the Office project templates in VS.NET 2003.

        Microsoft MVP, Visual C# My Articles

        D Offline
        D Offline
        Dimitris Iliopoulos
        wrote on last edited by
        #3

        Could you explain what exactly i have to do, i have to copy the assemblies in my runtime directory form %WINDIR%\assembly\gac and then add a reference to them thru the .NET tab and not the COM tab? I really appreciate your help From Greece: Dimitris Iliopoulos dimilio@yahoo.com

        H 1 Reply Last reply
        0
        • D Dimitris Iliopoulos

          Could you explain what exactly i have to do, i have to copy the assemblies in my runtime directory form %WINDIR%\assembly\gac and then add a reference to them thru the .NET tab and not the COM tab? I really appreciate your help From Greece: Dimitris Iliopoulos dimilio@yahoo.com

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          You'll need to copy those assemblies somewhere else to use them explicitly without the designer. Start a command prompt (cmd.exe in Windows NT-based OSes) and type:

          cd %windir%\assembly\gac
          dir

          You'll see a bunch of directories that match assembly names. You'll need to cd to each of those and then the version (should start with "11.") and copy those assemblies elsewhere, like C:\Program Files\Microsoft.NET\Office11 (recommended, where the Office10 assemblies get their own folder in that directory, which is the parent directory of the default .NET 1.1 SDK). The important thing is that you use the primary interop assemblies whenever possible. The way the interop assemblies are registered, however, VS.NET should've used the PIAs already. See, PIAs are typically generated by the company that produced the associated typelib and they are registered so that the typelib registry keys contain and entry that specify the PIAs associated with that typelib, so instead of creating a new typelib the old one is used. Before you do anything, I would look at the path of the Office assemblies you've already referenced and see if the path is C:\Windows\assembly\gac\....

          Microsoft MVP, Visual C# My Articles

          D 1 Reply Last reply
          0
          • H Heath Stewart

            You'll need to copy those assemblies somewhere else to use them explicitly without the designer. Start a command prompt (cmd.exe in Windows NT-based OSes) and type:

            cd %windir%\assembly\gac
            dir

            You'll see a bunch of directories that match assembly names. You'll need to cd to each of those and then the version (should start with "11.") and copy those assemblies elsewhere, like C:\Program Files\Microsoft.NET\Office11 (recommended, where the Office10 assemblies get their own folder in that directory, which is the parent directory of the default .NET 1.1 SDK). The important thing is that you use the primary interop assemblies whenever possible. The way the interop assemblies are registered, however, VS.NET should've used the PIAs already. See, PIAs are typically generated by the company that produced the associated typelib and they are registered so that the typelib registry keys contain and entry that specify the PIAs associated with that typelib, so instead of creating a new typelib the old one is used. Before you do anything, I would look at the path of the Office assemblies you've already referenced and see if the path is C:\Windows\assembly\gac\....

            Microsoft MVP, Visual C# My Articles

            D Offline
            D Offline
            Dimitris Iliopoulos
            wrote on last edited by
            #5

            I ,finally after lot of search, found what is the problem. It's a bug in office XP and office 2003. When you have installed the english version of office and you regional settings are not the same then you cannot call some functions, especially in Excel, and you have to use InvokeVerb so you tell with what exactly Culture Info you want to call the method. I lost really lot of time searching for this. By the way in office 2003 the PIA work good, you don't have to do the copy you have told, in Office XP there is this problem. Thanks a lot From Greece: Dimitris Iliopoulos dimilio@yahoo.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups