How to open an Excel file in C#?

Posted by tksy on Stack Overflow See other posts from Stack Overflow or by tksy
Published on 2009-01-21T11:25:48Z Indexed on 2010/03/29 20:03 UTC
Read the original article Hit count: 211

Filed under:

I am trying to convert some VBA code to C#. I am new to C#. Currently I am trying to open an Excel file from a folder and if it does not exist then create it. I am trying something like the following. How can I make it work?

Excel.Application objexcel;
Excel.Workbook wbexcel;
bool wbexists;
Excel.Worksheet objsht;
Excel.Range objrange;

objexcel = new Excel.Application();
if (Directory("C:\\csharp\\error report1.xls") = "")
{
    wbexcel.NewSheet();
}

else
{
    wbexcel.Open("C:\\csharp\\error report1.xls");
    objsht = ("sheet1");
}
objsht.Activate();

© Stack Overflow or respective owner

Related posts about c#