Using OLE DB to manipulate Excel, the error is prompted when you delete a table in Excel, it is strange (but it is not surprising, Microsoft's things like to give some inexplicable error hints), yesterday can be deleted, today will not be deleted (but yesterday to today there is really a big action, The system Ghost to the SSD, but the operation of the Excel file path has not changed.
detailed error message:
{System.Data.OleDb.OleDbException (0x80004005): The cell of the spreadsheet cannot be deleted.
At System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling (Oledbhresult hr)
In System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult (Tagdbparams dbparams, object& executeresult )
In System.Data.OleDb.OleDbCommand.ExecuteCommandText (object& executeresult)
In System.Data.OleDb.OleDbCommand.ExecuteCommand (CommandBehavior behavior, object& executeresult)
In System.Data.OleDb.OleDbCommand.ExecuteReaderInternal (CommandBehavior behavior, String method)
In System.Data.OleDb.OleDbCommand.ExecuteNonQuery ()
In Roadmap_Excel.Form1.button2_Click (Object sender, EventArgs e)
Related code:
Connection string:
//定义OleDB连接字符串 string"Provider=Microsoft.Ace.OleDb.12.0;Persist Security Info=False;""data source="@excelPath";Extended Properties=‘Excel 12.0; HDR=yes; IMEX=10‘"; new OleDbConnection(); conn.ConnectionString = strConn;
Code to execute the deletion:
Try{cmd =NewOleDbCommand ("Drop Table ["+ Roadmaptablename +"]", conn); Cmd. ExecuteNonQuery (); }Catch(System.ExceptionEx) {TextBox1.Text + = ("Delete data table failed:"+ ex. Message); TextBox1.Text + = ("\ r \ n");//The ISAM does not support the deletion of data in linked tables. cmd =NewOleDbCommand ("Delete from ["+ Roadmaptablename +"]", conn); Cmd. ExecuteNonQuery (); }
Really can't find the reason, then delete it manually.
No solution has been found, and there are no web pages to search for related issues.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
You cannot delete cells from a spreadsheet