且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OLEDB为EXCEL - 删除表[SHEETNAME $] - Doen't删除工作​​表

更新时间:2023-12-05 19:17:28

不幸的是,你不能删除使用ADO.NET为Excel工作表中。相反,你需要使用Excel互操作来执行这项任务。实际DELETE语句的基本代码将是这个样子:

Unfortunately, you cannot delete a worksheet using ADO.NET for Excel. Instead, you will need to use the Excel Interop to perform this task. The basic code for the actual DELETE statement would look something like this:

using MSExcel = Microsoft.Office.Interop.Excel;

private MSExcel._Application excel;
private MSExcel._Workbook workbook;
private MSExcel._Worksheet worksheet;
private MSExcel.Sheets sheet;

Excelapp.DisplayAlerts = false;
((Excel.Worksheet)workBook.Worksheets[3]).Delete();
Excelapp.DisplayAlerts = true;

这是它会怎样看的基本纲要。将DisplayAlerts线是解决一个问题有人曾与删除表。还要注意的是您不能删除最后一个表中的Excel文件即可。 。这个问题会得到你,如果你不看它

This is the basic rundown of how it would look. The DisplayAlerts lines are to fix an issue some people had with deleting a sheet. Also note that you cannot delete the last sheet in the Excel file. That issue will get you if you don't watch it.

下面是一些链接来帮助你:

Here are some links to help you out:

删除板href=\"http://msdn.microsoft.com/en-us/library/s9kdkks3%28VS.80%29.aspx\"> MSDN

MSDN on deleting sheeting in Excel

讨论后使用ADO.NET来DROP Excel中的一个表的可能性一>

SO质疑有关删除使用互操作在Excel工作表