删除Excel工作表编程 [英] delete excel worksheets programatically
本文介绍了删除Excel工作表编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个Excel工作簿很多很多张。我想删除除他们三人所有纸张。
具体而言,我想知道是否有一种方法使用工作表名称,而不是序(张数),除去张。
我使用Excel互操作和C#与Excel工作。
任何code /想法将是有益的。
Microsoft.Office.Interop.Excel.Application xlApp = NULL;
Excel.Workbook xlWorkbook = NULL;
Excel.Sheets xlSheets = NULL;
Excel.Worksheet xlNewSheet = NULL;
解决方案
xlApp.DisplayAlerts = FALSE;
对于(INT I = xlApp.ActiveWorkbook.Worksheets.Count; I> 0;我 - )
{
工作表wkSheet =(表)xlApp.ActiveWorkbook.Worksheets [I]
如果(wkSheet.Name ==NameOfSheetToDelete)
{
wkSheet.Delete();
}
}
xlApp.DisplayAlerts = TRUE;
have an excel workbook with many, many sheets. I want to delete all the sheets except for three of them.
specifically, i would like to know if there is a way to remove the sheets using sheet name instead of ordinals (sheet number).
i am using excel interop and C# to work with Excel.
any code / ideas would be helpful.
Microsoft.Office.Interop.Excel.Application xlApp = null;
Excel.Workbook xlWorkbook = null;
Excel.Sheets xlSheets = null;
Excel.Worksheet xlNewSheet = null;
解决方案
xlApp.DisplayAlerts = false;
for (int i = xlApp.ActiveWorkbook.Worksheets.Count; i > 0 ; i--)
{
Worksheet wkSheet = (Worksheet)xlApp.ActiveWorkbook.Worksheets[i];
if (wkSheet.Name == "NameOfSheetToDelete")
{
wkSheet.Delete();
}
}
xlApp.DisplayAlerts = true;
这篇关于删除Excel工作表编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文