Get the available sheets present in Excel

Jun 12, 2014 at 2:13 PM
I need to know the method to get the available sheets present in the excel file. Is there any predefined functions or Methods???

Please Help me...
Jun 12, 2014 at 3:11 PM
Edited Jun 12, 2014 at 3:17 PM
There is no predefined function. For our own application, I had to implement a new method, first in the interface:
        /// <summary>
        /// Retrieves the names of the worksheets
        /// </summary>
        /// <returns>A list containing the names of the worksheets</returns>
        List<string> GetWorksheetNames();
and then in ExcelBinaryReader.cs:
        public List<string> GetWorksheetNames()
        {
            List<string> namesList = new List<string>();
            foreach (XlsWorksheet worksheet in m_sheets)
            {
                namesList.Add(worksheet.Name);
            }

            return namesList;
        }
and ExcelOpenXmlReader.cs:
        public List<string> GetWorksheetNames()
        {
            List<string> namesList = new List<string>();
            for (int ind = 0; ind < _workbook.Sheets.Count; ind++)
            {
                namesList.Add(_workbook.Sheets[ind].Name);
            }

            return namesList;
        }
I submitted this and other changes allowing for a single worksheet to be retrieved into a DataTable (as opposed to the entire workbook into a DataSet) for consideration to be included in the next version of the Excel Data Reader.

To obtain the list of worksheets with the current Excel Data Reader code, you would have to call AsDataset() to load the entire workbook into a DataSet, and then iterate through the dataset's data tables to retrieve their names. By then, though, the content of the entire Excel file has been read.