943,634 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1805
  • C# RSS
Dec 6th, 2008
0

error opening excel sheet in c#

Expand Post »
i'm trying to open an existing excel worksheet. my code is:

c# Syntax (Toggle Plain Text)
  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 ?
Similar Threads
Reputation Points: 20
Solved Threads: 0
Junior Poster
emilio is offline Offline
162 posts
since Nov 2007
Dec 6th, 2008
0

Re: error opening excel sheet in c#

Why not use a pathname like @"C:\....\Test.xls" ?
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,736 posts
since Oct 2008
Dec 6th, 2008
0

Re: error opening excel sheet in c#

Are you sure about the path wheather it is right or not
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Dec 7th, 2008
0

Re: error opening excel sheet in c#

i tried it with an absolute path like "c:\Data.xls" and it works fine.
the problem is with relative path.
Reputation Points: 20
Solved Threads: 0
Junior Poster
emilio is offline Offline
162 posts
since Nov 2007
Dec 7th, 2008
0

Re: error opening excel sheet in c#

Read this http://weblogs.asp.net/pwelter34/arc...e-snippet.aspx
it might help.
It is also possible that Open only accepts absolute paths.
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,736 posts
since Oct 2008
Dec 7th, 2008
0

Re: error opening excel sheet in c#

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.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How to insert data in GridView and then into database
Next Thread in C# Forum Timeline: Displaying a local webpage





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC