Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unable to delete an Excel 2007 (*.xlsx) worksheet using Ole Db

12 views
Skip to first unread message

Advantimech

unread,
Dec 30, 2009, 4:06:02 PM12/30/09
to
Hello,

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;
}
}

Advantimech

unread,
Dec 31, 2009, 9:21:01 AM12/31/09
to
I should have mentioned that the connection string that I used is
"Provider=Microsoft.Ace.OLEDB.12.0;Data
Source=C:\Office2007\TestFile.xlsx;Extended Properties="Excel 12.0
Xml;HDR=YES".
0 new messages