Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:31pm
Edited 26-Jun-12 21:49pm
496.2K
v2
Comments
Sandeep Mewara at 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 at 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
0 OriginalGriff 205
1 Sergey Alexandrovich Kryukov 185
2 jlopez788 144
3 Rob Philpott 100
4 Prakriti Goyal 97
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,589
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2014
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