-1

My requirement is to open an excel book using c#. (ie) Am creating an excel and writing the stuffs which are needed to be entered in excel and saving it in a location .In final am showing user a yesorno box with messgae do you need to open the excel. If user selects option YES then i need to open the excel from the path where i saved and need to show the user by excel open . I tried the following for opening the excel application using c#,but excel is not getting opened.

Application excel = new Application();
Workbook wb = excel.Workbooks.Open(path);

Thanks in advance

Dah Sra
  • 4,107
  • 3
  • 30
  • 69

1 Answers1

-1

Your not opening Excel the correct way to show it. now its running as a background process.

I suggest following this tutorial as it includes all you need to now about Excel to do what you ask for.

to quickly start a excel application you could use the following code:

Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

After starting the application you can use the code from the tutorial to create work sheets and edit cells in the file.

To do all of this you would need the following using on top of your file:

using Excel = Microsoft.Office.Interop.Excel; 

Keep in mind you also need to reference the excel library in your project.

Nick Otten
  • 702
  • 7
  • 17
  • While the linked article may answer the question, link-only answers are discouraged, as noted here: http://stackoverflow.com/help/how-to-answer. – Tieson T. Dec 24 '14 at 07:55
  • @TiesonT.I do agree to this rule when it goes about really detailed questions. But in this case the tutorial I linked contains more source code, details and background information then I could type up out the top of my head. Sure I could write the code out myself but that would supply the user with a less detailed answer. Or I could copy the example from that website to here, but that would do no credit to the actual author of the example. I'll edit my answer giving the person some more background info. But I still strongly suggest he reads that tutorial or hes stuck again within minutes. – Nick Otten Dec 24 '14 at 08:08
  • Generally speaking, if your answer needs to be excessively long to be useful, then that's an indication that the question itself is not reasonably scoped and you should probably not be answering it. Ideally, your link would have been a better fit as a comment, with the user returning to ask a more specific question that *can* be reasonably answered on StackOverflow. – Tieson T. Dec 24 '14 at 08:18
  • @TiesonT. That is a fair point, I post it as a comment next time. – Nick Otten Dec 24 '14 at 08:33
  • @NickOtten : I want to open excel application. (ie) need to start the excel application with saved sheet and show to theuser – Dah Sra Dec 24 '14 at 09:04