Hallo!
I am trying to open an excel file using the following code which is written in a class library that I created in my project.
string mySheet = @"C:\Users\Tal\Desktop\DataBase.xlsx";
var excelApp = new Excel.Application();
excelApp.Visible = true;
Workbook wb = excelApp.Workbooks.Open(mySheet);
Worksheet ws = (Worksheet)wb.Worksheets[1];
Excel.Range xlRange = ws.UsedRange;
When I try to run the program it stops when it trys to execute the following command line:
" Workbook wb = excelApp.Workbooks.Open(mySheet);"
It says it can not find the excel file and asks me to check if the location of the file that I inserted is write properly. I know for sure that the file location is right because when I'm trying to run the same program on the console application it all works just fine.
If anyone knows how to make this program to work on the windows form too, I would be very happy if he could help me to do so.
Thanks, Tal.
Hi again,
I have some updates related to my problem that I wanted to fill you in about.
Apparently the problem I told you about is even bigger than I thought. I found out that the program doesn't work properly but only on my computer. Now, it's not even working on the console application as it was before. In both platforms(console application and windows form) the program stops, and the same error message appears.
However, when I try to run the program on a different computer it work's exactly as it should and the Excel file is displayed. I should of say though, that there are three basic differences between the two computers which I think might couse this problem.
Firt, on my computer (the one where the code doesn't compile) windows 8 is used as the operating system and on the other computer windows 7 is installed.
The second difference between the two computers is that on my computer I have the Excel 2010 and on the other one the 2007 version.
In order to work with Excel, I need to add the Microsoft Excel Object Libary refrence. On my computer it is the 14.0 version, while on the other computer it is the 12.0 version.
Please let me know if you think that the problem is related to one of the differences I mentioned above, and if not, I would be very happy to hear for any other suggestions you might have, that could help me solve this problem.
Thanks again, Tal.