You must Sign In to post a response.
  • Category: .NET

    To open an excel sheet using windows forms

    using System.Windows.Forms;

    using Excel = Microsoft.Office.Interop.Excel;



    namespace WindowsApplication1

    {

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    }



    private void button1_Click(object sender, EventArgs e)

    {

    Excel.Application xlApp ;

    Excel.Workbook xlWorkBook ;

    Excel.Worksheet xlWorkSheet ;

    object misValue = System.Reflection.Missing.Value;



    xlApp = new Excel.ApplicationClass();

    xlWorkBook = xlApp.Workbooks.Open("csharp.net-informations.xls", 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);



    MessageBox.Show(xlWorkSheet.get_Range("A1","A1").Value2.ToString());



    xlWorkBook.Close(true, misValue, misValue);

    xlApp.Quit();



    releaseObject(xlWorkSheet);

    releaseObject(xlWorkBook);

    releaseObject(xlApp);

    }



    private void releaseObject(object obj)

    {

    try

    {

    System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);

    obj = null;

    }

    catch (Exception ex)

    {

    obj = null;

    MessageBox.Show("Unable to release the Object " + ex.ToString());

    }

    finally

    {

    GC.Collect();

    }

    }

    }

    }
  • #681260
    please refer below link

    http://csharp.net-informations.com/excel/csharp-open-excel.htm


    http://www.codeproject.com/Articles/5123/Opening-and-Navigating-Excel-with-C

  • #681273
    hi,

    Did you got any error? or share code?

    Regards
    N.Ravindran
    Your Hard work never fails


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.