title: Listing excel tables with OleDbConnection::GetOleDbSchemaTable()
body: <p>The following PowerShell snippet will list all worksheets and named ranges in an excel spreadsheet via <a href="http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.getoledbschematable.aspx" rel="nofollow">OleDbConnection.GetOleDbSchemaTable()</a>:</p>
  
  <pre><code>$file = "C:\Users\zippy\Documents\Foo.xlsx";
  $cnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=`"$($file)`";Extended Properties=`"Excel 12.0 Xml;HDR=YES`";";
  
  
  $cn = New-Object System.Data.OleDb.OleDbConnection $cnStr;
  $cn.Open();
  
  # to list the sheets
  $worksheets = $cn.GetOleDbSchemaTable([System.Data.OleDb.OleDbSchemaGuid]::Tables,$null);
  $cn.Close();
  $cn.Dispose();
  $worksheets | Format-List;
  </code></pre>
  
  <p>This will however, not list tables (called lists in Excel 2003), or a named range that refers to a list.</p>
  
  <p>If I pass an <a href="http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbschemaguid.aspx" rel="nofollow">OleDbSchemaGuid</a> of type Procedures or Views I get a <a href="http://msdn.microsoft.com/en-us/library/system.management.automation.methodinvocationexception%28v=vs.85%29.aspx" rel="nofollow">MethodInvocationException</a> with a message of <code>Operation is not supported for this type of object.</code></p>
  
  <p>Is this possible to list the tables by tweaking with the connection strings or restrictions parameter?</p>