Quantcast
Channel: Excel Data Reader - Read Excel files in .NET
Viewing all articles
Browse latest Browse all 448

New Post: Get the available sheets present in Excel

$
0
0
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.

Viewing all articles
Browse latest Browse all 448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>