Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have some code that has been working relatively well. Some excel books give me odd sheets, like the print area pages, and other meta data tables

System.Data.DataTable dt = Connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            foreach (System.Data.DataRow dr in dt.Rows)
            {
                WorkSheets.Add(dr["TABLE_NAME"].ToString());
            }
            Connection.Close();



How can I fix this to get just the data sheets?
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jan-12 1:07am    
Fix what, exactly?
--SA
loctrice 19-Jan-12 8:21am    
I don't know how I could change it to be more clear, or I would. It doesn't just get worksheet1, worksheet2,etc... It gets other sheets with Print_Area appended. I just want the data/worksheets.
loctrice 19-Jan-12 10:04am    
I'm not entirely sure why my question deserves a down vote. I explained the problem I was having, gave the code I was using, and clearly stated a question.

Connect using the Excel Object instead of using OleDB. http://msdn.microsoft.com/en-us/library/wss56bz7(v=VS.80).aspx[^]
 
Share this answer
 
v2
Comments
fjdiewornncalwe 19-Jan-12 12:36pm    
Just fixed your link.
loctrice 19-Jan-12 13:23pm    
I need to stick with OleDB.
You may try OleDbSchemaGuid.Views as well and then do a difference between what OleDbSchemaGuid.Tables gives you and the views give you.
 
Share this answer
 
Comments
loctrice 19-Jan-12 16:44pm    
This got me searching in the right direction again. I wasn't getting anything back in google the ways I was trying to search. Thanks.
loctrice 24-Jan-12 10:01am    
I found a solution by adding the sheet name only if it ends with $. That seems to work well. Thanks again for the push.

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