Click here to Skip to main content
12,749,754 members (37,456 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
public void btnBrowse_Click(object sender, EventArgs e)
        {
            string ExcelFile;
            int TotalSheets;
            Excel.Application Exapp;
            Microsoft.Office.Interop.Excel.Workbook Myworkbook;
            
            cbmFile.Items.Clear();
            txtFile.Text = "";
            try
            {
                
                OpenFileDialog1.Filter = "Excel Files (*.xls)|*.xls|All Files(*.*)|*.*";
                OpenFileDialog1.InitialDirectory = @"c:\";
                OpenFileDialog1.FileName = "Select File";
                OpenFileDialog1.Title = "Select excel file..";
                OpenFileDialog1.ShowDialog();
                ExcelFile = OpenFileDialog1.FileName; ;
                txtFile.Text = ExcelFile;
                Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Workbook workbook = Exapp.Workbooks.Open(ExcelFile, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                TotalSheets = Myworkbook.Worksheets.Count;
                foreach (Excel.Worksheet wksh in Myworkbook.Worksheets)
                {
                    cbmFile.Items.Add(wksh.Name);
                }
                Myworkbook.Close(false, false, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Posted 26-Jun-12 22:31pm
Updated 26-Jun-12 22:49pm
v2
Comments
Sandeep Mewara 27-Jun-12 3:49am
   
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
ryanb31 27-Jun-12 8:24am
   
What is the question?

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

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100