Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I want to skip reading those excel sheets which are hidden , while importing data from excel. I am using the code as below, but i have not added the code here . Can anyone please help me

C#
using (OleDbConnection conn = new OleDbConnection(oledbConn))
            {
                if (conn.State != Data.ConnectionState.Open)
                    conn.Open();

                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = conn;


                // Get all Sheets in Excel File
                Data.DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);

                // Loop through all Sheets to get data
                foreach (Data.DataRow dr in dtSheet.Rows)
                {
                    sheetName = dr["TABLE_NAME"].ToString();

                    if (!sheetName.EndsWith("$") || sheetName.StartsWith("VSTS_Validation"))
                        continue;

                    // Get all rows from the Sheet
                    cmd.CommandText = "SELECT * FROM [" + sheetName + "]";

                    Data.DataTable dt = new Data.DataTable();
                    dt.TableName = sheetName;


                    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                    da.Fill(dt);

                    dsWorkitems.Tables.Add(dt);
                }
Posted
Comments
hypermellow 17-Sep-14 9:50am    
Does your code try to read from the hidden sheets?
... I though hidden sheet ended with an underscore character, and visible sheets with a dollar?
Arjun Menon U.K 17-Sep-14 9:57am    
It aint like that . Sorry .All excel sheet name ends with $ whether its hidden or not
hypermellow 17-Sep-14 10:17am    
Ah no worries, it must have been the older .xls format that had the underscore appended to the hidden sheet names.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900