We help IT Professionals succeed at work.

Results from OleDbConnection.GetSchema("Tables")

anyoneis
anyoneis asked
on
10,794 Views
Last Modified: 2013-12-17
I am using C# and ADO.NET to read an Excel workbook with multiple worksheets. When I use the code below, I get multiple entries for each sheet.

For example, I have a sheet named "Plate_2". When I do the GetSchema call, I see entries for "Plate_2" and one for "Plate_2$".

More confusing, for the sheet named "Plate_3", I have "Plate_3", "Plate_3$", and "Plate_3$_".

Which of these is the worksheet? Why are there threee different entries? What do the differences indicate? Are there any other funky things like "Print_Area" which I should expect to see?

Thanks,
David

[Code]
        public static string LoadWorkbookSchema(string workbookPath, ref DataTable dtWorksheets)
        {
            try
            {
                using (OleDbConnection connection = GetWorkbookConnection(workbookPath))
                {
                    dtWorksheets = connection.GetSchema("Tables");
                }
                foreach (DataRow dr in dtWorksheets.Rows)
                {
                    if (dr["TABLE_NAME"].ToString().EndsWith("Print_Area"))
                        dr.Delete();
                }
            }
            catch (Exception exception)
            {
                return exception.Message;
            }
            return "";
        }


        public static OleDbConnection GetWorkbookConnection(string WorkBookPath)
        {
            // Note that IMEX=1 was added to eliminate problems with data in the "9th-plus line"
            // having a different data format than the first 8. dwr
            string connectionString =
                string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1""",
                    WorkBookPath);

            OleDbConnection connection = new OleDbConnection(connectionString);
            connection.Open();
            return connection;
        }


[/Code]
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
anyoneisSoftware Developer
Top Expert 2006

Author

Commented:
Correct! The "unadorned" names (no dollah, no quote, no...) appear to be named ranges. That's part of it. "Excel schema anomalies for 200, Alex."

:-David
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
David,

The normal worksheet name is Plate_3$, all the others are not normal table names.  OleDb doesn't distinguish between the table types, as far as I know.  

Bob
anyoneisSoftware Developer
Top Expert 2006

Author

Commented:
I'm going to leave this open for a bit longer to see if someone knows what "Plate_3$_" might be....

I still don't know what the ones ending in an '_' are, but I can ignore them for now and just crunch the worksheets. Thanks, Bob.

David
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
anyoneisSoftware Developer
Top Expert 2006

Author

Commented:
Excellent! It was obvious in the xml. I discovered:

  <Names>
   <NamedRange ss:Name="_FilterDatabase" ss:RefersTo="=Plate_3!R1C1:R97C13"
    ss:Hidden="1"/>
  </Names>

I changed the ss:Hidden attribute value to "0", save the file and reopened it, and the named range showed up.

grazie!
David

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.