473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

'System.InvalidCastException'

Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation)
in my windows form...
I got the Exception

'System.InvalidCastException' : QueryInterface for interface
Excel._Application failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien
Nov 15 '05 #1
7 4696
Julien,

Is it possible that you are running this on a machine that has a
different version of Excel than the product was developed for? If so, then
you will have to resort to either late binding, or performing a conditional
switch, and have references to each version's interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Julien" <ju************@heuft.com> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation)
in my windows form...
I got the Exception

'System.InvalidCastException' : QueryInterface for interface
Excel._Application failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien

Nov 15 '05 #2
I am trying to develop with excel 2000, maybe it will be better that I try
Excel XP !!!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: #t**************@TK2MSFTNGP10.phx.gbl...
Julien,

Is it possible that you are running this on a machine that has a
different version of Excel than the product was developed for? If so, then you will have to resort to either late binding, or performing a conditional switch, and have references to each version's interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Julien" <ju************@heuft.com> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation) in my windows form...
I got the Exception

'System.InvalidCastException' : QueryInterface for interface
Excel._Application failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien


Nov 15 '05 #3
It might help if you would post some code of the problem.
My guess is that what you are trying to send to excel isn't something
excel can handle.
Not sure what changing cultureinfo would fix. Then again, some code would
be helpful.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4
Julien,

Where did you get the primary interop assemblies that you are using in
..NET to access Excel from?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Julien" <ju************@heuft.com> wrote in message
news:ua**************@TK2MSFTNGP12.phx.gbl...
I am trying to develop with excel 2000, maybe it will be better that I try
Excel XP !!!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> a écrit
dans le message de news: #t**************@TK2MSFTNGP10.phx.gbl...
Julien,

Is it possible that you are running this on a machine that has a
different version of Excel than the product was developed for? If so,

then
you will have to resort to either late binding, or performing a

conditional
switch, and have references to each version's interfaces.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Julien" <ju************@heuft.com> wrote in message
news:eL**************@TK2MSFTNGP09.phx.gbl...
Hi !!!

I hav a problem when I try to initialize my workbook (opening or creation) in my windows form...
I got the Exception

'System.InvalidCastException' : QueryInterface for interface
Excel._Application failed

I tried to change de CultureInfo but it doesn't work better.
I am working with VS.Net and Excel 2000

is there something else to do ?

thanks

Julien



Nov 15 '05 #5
Thanks for replying, here is the code :

================================================== =====
private Excel.Application ExcelObj = null;

public Form1()
{
// Initialize the Windows Components
InitializeComponent();
ExcelObj = new Excel.Application();
// See if the Excel Application Object was successfully constructed
if (ExcelObj == null)
{
MessageBox.Show("ERROR: EXCEL couldn't be started!");
System.Windows.Forms.Application.Exit();
}
}

private void menuItem2_Click(object sender, System.EventArgs e)
{
// *** open the workbook --> it goes wrong on this line
Excel.Workbook theWorkbook =
ExcelObj.Workbooks.Open("c:\counter.xls",Type.Miss ing, Type.Missing,
Type.Missing,Type.Missing,Type.Missing, Type.Missing,
Excel.XlPlatform.xlWindows, Type.Missing,Type.Missing,
Type.Missing,Type.Missing, Type.Missing);
// *** get the collection of sheets in the workbook
Excel.Sheets sheets = theWorkbook.Worksheets;
// *** get the first and only worksheet from the collection of worksheets
Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1);
....
}
================================================== =============

concerning the primary interop assemblies, under VS.Net I choose project>add
a reference>COM and then I select "Microsoft Excel 9 Object Librairy",
filename is "excel9.olb" ; it puts the interop.excel.dll and
interop.office.dll in my project folder... I have problem to understand the
what is Interop...

Thanks for your help
__________________________________________________ ___________________
"Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de
news: oprxs3y0dbhntkfz@localhost...
It might help if you would post some code of the problem.
My guess is that what you are trying to send to excel isn't something
excel can handle.
Not sure what changing cultureinfo would fix. Then again, some code would
be helpful.

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #6
> // *** open the workbook --> it goes wrong on this line
Excel.Workbook theWorkbook =
ExcelObj.Workbooks.Open(

"c:\counter.xls",
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlPlatform.xlWindows,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);

Something among these paramteres is of the wrong type, but I couldn't find
much reference to WoorkBooks.Open in my helpfiles or MSDN, so I'm not sure
what it expects.

http://www.dotnet247.com/247referenc...22/113113.aspx
used this method to open a woorkbook

Excel.Workbook Workbook = objExcel.Workbooks.Open(
ImportFileName,
0,
true,
5,
"",
"",
true,
Excel.XlPlatform.xlWindows,
"\t",
false,
false,
0,
false);
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #7
I already try all possibilities but nothing works... I don't know if this is
the code but maybe it comes from the interops ??
"Morten Wennevik" <Mo************@hotmail.com> a écrit dans le message de
news: oprxs6x0wehntkfz@localhost...
// *** open the workbook --> it goes wrong on this line
Excel.Workbook theWorkbook =
ExcelObj.Workbooks.Open(

"c:\counter.xls",
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Excel.XlPlatform.xlWindows,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);

Something among these paramteres is of the wrong type, but I couldn't find
much reference to WoorkBooks.Open in my helpfiles or MSDN, so I'm not sure
what it expects.

http://www.dotnet247.com/247referenc...22/113113.aspx
used this method to open a woorkbook

Excel.Workbook Workbook = objExcel.Workbooks.Open(
ImportFileName,
0,
true,
5,
"",
"",
true,
Excel.XlPlatform.xlWindows,
"\t",
false,
false,
0,
false);
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bob scola | last post by:
I have a csharp, VS 2003 solution for a winform application The application uses an object called a "matter" and the class is defined in matter.cs. I can load matter objects into a combobox ...
1
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm...
4
by: DOTNET | last post by:
Hi, Anybody help me regarding this error: I am assigning the values to the session variables when the button is clicked and passing these session variables to the next page and when I am...
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
2
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) {...
1
by: Ratz | last post by:
Hello everyone! I'm new to this Forum! I've spent about 56 hours trying to solve a .NET VB Runtime error while Using a program.Ive contacted the developer of the program and he could not figure out...
8
by: Gamma | last post by:
I'm trying to inherit subclass from System.Diagnostics.Process, but whenever I cast a "Process" object to it's subclass, I encounter an exception "System.InvalidCastException" ("Specified cast is...
8
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i trying to collect windows services. i'm getting inconsistencies. the collection works every time locally. but remote collection yields different result depending on my lab environment. 1) in...
4
by: rsdev | last post by:
Hi, I have an InvalidCastException which is completely puzzling me. I have checked all the members in the stored procedure against my data provider and seems to be ok. Also in the stack trace it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.