title: I am getting invalid sheetnames from Excel files using OleDb. What's wrong?
body: <p>I try to get excel sheet names, with oledb. </p>
  
  <p>My connection string is:</p>
  
  <pre><code>"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
  filepath + 
  ";Extended Properties=Excel 12.0;";
  </code></pre>
  
  <p>where <code>filepath</code> is a filename.</p>
  
  <p>My code for this:</p>
  
  <pre><code>List&lt;string&gt; sheetNames = new List&lt;string&gt;();
  _excel.Connect(_path);
  DataTable dataTable = _excel.ExecuteSchema();
  _excel.Disconnect();
  foreach (DataRow row in dataTable.Rows)
  {
      string sheetName = row["TABLE_NAME"].ToString();
      if(!sheetName.EndsWith("$'")) { continue; }
      sheetNames.Add(sheetName);
   }
  </code></pre>
  
  <p>the list with the sheets names contains all valid sheet names and some other sheet names.
  Example:</p>
  
  <ul>
  <li><code>"'correctsheetname$'"</code></li>
  <li><code>"'correctsheetname$'Print_Area"</code></li>
  </ul>
  
  <p>I only add sheets that end in <code>$'</code></p>
  
  <p>My problem is that if a sheet name contains a single quote, I get it with two single quotes.</p>
  
  <p>Example: 
   for sheet named <code>asheetname's</code> I get <code>'asheetname''s$''</code></p>
  
  <p>Afterwards, when I try to get the datasource of this sheet, I am getting an exception that this sheet doesn't exist.</p>
  
  <pre><code>query = "SELECT * FROM ['asheetname''s$']"
  _command = new OleDbCommand(query, _connection);
  _dataTable = new DataTable();
  _dataReader = _command.ExecuteReader();   &lt;-- Exception is thrown here
  </code></pre>
  
  <p>And the exception message:</p>
  
  <p><code>{System.Data.OleDb.OleDbException: ''asheetname''s$'' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
     at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
     at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object&amp; executeResult)
     at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object&amp; executeResult)
     at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object&amp; executeResult)
     at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
     at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
     at System.Data.OleDb.OleDbCommand.ExecuteReader()
     at PrestaImporter.Entity.Excel.ExecuteQuery(String query)</code></p>