Click here to Skip to main content
Sign Up to vote bad
good
See more: 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 - 21:31
Edited 26 Jun '12 - 21:49

Comments
Sandeep Mewara - 27 Jun '12 - 3:49
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:24
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 206
1 Maciej Los 146
2 Richard MacCutchan 145
3 Tadit Dash 140
4 Sergey Alexandrovich Kryukov 135
0 Sergey Alexandrovich Kryukov 10,264
1 OriginalGriff 7,957
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,155


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