OLEDB为EXCEL - 删除表[SHEETNAME $] - Doen't删除工作​​表 [英] OLEDB for EXCEL - Drop Table [SheetName$] - Doen't Delete Sheet

查看:970
本文介绍了OLEDB为EXCEL - 删除表[SHEETNAME $] - Doen't删除工作​​表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DROP TABLE [SHEETNAME $]删除从Excel工作表中。

I am using drop table [SheetName$] to delete a worksheet from excel.

这只是清除表的数据,但不删除工作表。

我已经使用XLS和XLSX尝试。 !没有这两种版本

I have tried using xls and xlsx. Doesn't work with both versions !

OleDbConnection connection = new OleDbConnection();

try
{
connection.ConnectionString =
@"Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='drop.xlsx";
connection.Open();
OleDbCommand command = new OleDbCommand("Drop Table [MySheetName_1$]", connection);
command.ExecuteNonQuery();
}
finally
{
connection.Close();
}



任何帮助/指针感谢!
谢谢

Any Help / Pointers appreciated ! Thanks

推荐答案

不幸的是,你不能删除使用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工作表

这篇关于OLEDB为EXCEL - 删除表[SHEETNAME $] - Doen't删除工作​​表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆