error opening excel sheet in c#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 144
Reputation: emilio is an unknown quantity at this point 
Solved Threads: 0
emilio emilio is offline Offline
Junior Poster

error opening excel sheet in c#

 
0
  #1
Dec 6th, 2008
i'm trying to open an existing excel worksheet. my code is:

  1. Microsoft.Office.Interop.Excel.Application excelApp;
  2. Microsoft.Office.Interop.Excel.Workbook excelWorkbook;
  3. Microsoft.Office.Interop.Excel.Worksheet ExlWrkSheet;
  4. private object Opt = Type.Missing
  5.  
  6. excelApp = new ApplicationClass();
  7.  
  8. excelWorkbook = excelApp.Workbooks.Open("..//..//Data.xls", Opt, Opt, Opt, Opt, Opt, Opt, Opt, Opt, Opt, Opt, Opt, Opt, Opt, Opt);

on the last line i get an exception that he cannot find the file.
i placed the file in the project directory.
i tried also "Data.exl" path when the file is placed in the debug directory, it didn't helped.

what am i doing wrong ?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,984
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 289
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: error opening excel sheet in c#

 
0
  #2
Dec 6th, 2008
Why not use a pathname like @"C:\....\Test.xls" ?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

Re: error opening excel sheet in c#

 
0
  #3
Dec 6th, 2008
Are you sure about the path wheather it is right or not
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 144
Reputation: emilio is an unknown quantity at this point 
Solved Threads: 0
emilio emilio is offline Offline
Junior Poster

Re: error opening excel sheet in c#

 
0
  #4
Dec 7th, 2008
i tried it with an absolute path like "c:\Data.xls" and it works fine.
the problem is with relative path.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,984
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 289
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: error opening excel sheet in c#

 
0
  #5
Dec 7th, 2008
Read this http://weblogs.asp.net/pwelter34/arc...e-snippet.aspx
it might help.
It is also possible that Open only accepts absolute paths.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: error opening excel sheet in c#

 
0
  #6
Dec 7th, 2008
Open does except relative paths, however, you have to be sure of where you are vs where your file is which is often unlikely.

So, if you have your app, and you are sure you are in your exe's directory, then opening "Data/file" will work - but, for example, excel may not be in the apps directory but its own, you can tell by using the filemonitor from microsoft (seeing as they bought the company out) which will show you where it was trying to find the file.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC