Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I tried to open an excel sheet... but this code is not working ...

string path = Session["dir"].ToString() + "\\" + e.CommandArgument.ToString();
\\path = E:\\PO\\1.xls
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;

xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();

releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
Posted
Updated 20-Apr-14 23:57pm
v2
Comments
Mehdi Gholam 21-Apr-14 5:55am    
"not working" is not informative if you want help.
Sriram Ramachandran 21-Apr-14 5:58am    
I mean I couldn't find the problem in above code ... No output ...
ZurdoDev 21-Apr-14 7:09am    
All you do is open it and then close it. What do you expect to happen?

Hi,

I think you need to review How to open Excel XLS file in C#.net[^], this will help you.
 
Share this answer
 
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "EXCEL.EXE";
startInfo.Arguments = System.IO.Path.Combine(Session["dir"].ToString(), e.CommandArgument.ToString());
Process.Start(startInfo);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900