5 Replies - 967 Views - Last Post: 12 June 2013 - 11:26 PM Rate Topic: -----

#1 varunit  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 03-September 09

Excel and C# Interop

Posted 10 June 2013 - 09:43 AM

I'm developing an application which needs to interact with Excel sheets for various reasons. It will read from existing Excel sheets and create new sheets out of the data read. I searched and found that I can make use of Interop to achieve it.

I added a reference to the Interop Assembly and created the usual

using Excel = Microsoft.Office.Interop.Excel;

Excel._Application xlApp = new Excel.Application();
Then Excel._Workbook and Excel.Worksheet in similar fashion.

The program ran successfully without any errors.

But However while running I'm beging thrown an Exception that COM class failed to Load for CLSID and error code is 80040154.

I searched threads similar to the above issue and the solution given was to modify platform target as x86 instead of Any CPU. I did that and the problem still remains.

One more solution provided was to edit DCOM and regsrvr32.exe to allow application to a full trust and one other solution was to create another user account.

I cannot do them because I cannot login with administrator privileges. Also I cannot install any other excel libraries like openXML for same reason.

I need a way to get rid of that exception and continue building my application using the Interop Assembly. I'm 100% sure that .NET framework, Visual Studio 2008 Professional Edition and MS Office are already installed in the server.

Can anyone help me out please?

Is This A Good Question/Topic? 0
  • +

Replies To: Excel and C# Interop

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3169
  • View blog
  • Posts: 9,595
  • Joined: 05-May 12

Re: Excel and C# Interop

Posted 10 June 2013 - 09:55 AM

Is your code running as a Windows application, a Windows service, a Web Application, or a Web Service? Please note that Microsoft only supports using the automation methods for the first case: Windows application.

http://support.microsoft.com/kb/257757

If you know that you are using only Office 2007 and later Excel files, the Packaging namespace in the .NET Framework will let you get access to the data in the Excel file, but not necessarily in a very fluent manner. You'll have to build up some helper classes to help.
Was This Post Helpful? 0
  • +
  • -

#3 varunit  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 03-September 09

Re: Excel and C# Interop

Posted 10 June 2013 - 08:49 PM

My application is a Windows Forms app. I've built an app in the same environment which used Interop Word. It ran fine without any exceptions.

Also I have to use only Excel 2003, but Excel 2007 files will open and work since compatability pack is installed.

Is there any way I could make use of the VSTO libraries and access Excel classes?
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3169
  • View blog
  • Posts: 9,595
  • Joined: 05-May 12

Re: Excel and C# Interop

Posted 10 June 2013 - 09:25 PM

Please paste the entire error message including the CLSID of the class it is trying to instantiate.

Also post your code and please tell us which line is throwing the exception.

Also what version of Excel do you have installed: the 32-bit or 64-bit version?

And lastly, can you run corflags.exe on your WinForms app just to double check that your are truly building for x86.

This post has been edited by Skydiver: 10 June 2013 - 09:26 PM

Was This Post Helpful? 0
  • +
  • -

#5 varunit  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 03-September 09

Re: Excel and C# Interop

Posted 12 June 2013 - 08:57 PM

As I already mentioned, Unfortunately, I don't have permissions to run any third party tools like corflags. The thing is I', develeoping in a server environment. Application fails at the like

Excel.Application xl = new Excel.Application(); line by itself.

I also tried this time for Word Interop, it also failed surprisingly with the same error.
However, when I run my app inside another server, it ran successfully without any exceptions. I'm assuming this is an environmental issue.

Thank you skydiver for the suggestions :)
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3169
  • View blog
  • Posts: 9,595
  • Joined: 05-May 12

Re: Excel and C# Interop

Posted 12 June 2013 - 11:26 PM

corflags.exe should have been installed with Visual Studio into one of the SDK directories. If you can compile code, then you can run corflags.exe on the commandline.

Is Office even installed on those servers where you are getting a failure?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1