Excel 2003 interop
-
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
-
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
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
-
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
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
-
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
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
dirYou'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
-
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
dirYou'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
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