I have a C# app where it allows the user to delete a worksheet from an Excel
workbook. The code works well with any Excel 2000-2003 workbook (*.xls).
However, when it comes to the new 2007 format, all it does is clearing out
the worksheet and not removing them as I would expected. I attach the
portion of the codes below. Please help.
Thanks!
public bool DeleteWorksheet(string worksheetName)
{
try
{
if (this.Connection.State != ConnectionState.Open)
{
this.Connection.Open();
}
string cmdText = "DROP TABLE [{0}]";
using (OleDbCommand cmd = new OleDbCommand(
string.Format(cmdText, worksheetName),
this.Connection))
{
cmd.ExecuteNonQuery();
}
this.Connection.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}