移除工作表
Contents
[
Hide
]
本主题提供有关如何使用Aspose.Cells.GridWeb API从Microsoft Excel文件中删除工作表的信息。可以通过指定工作表索引或名称来删除工作表。
删除工作表
使用工作表索引
下面的代码显示了如何通过在GridWorksheetCollection的RemoveAt方法中指定工作表索引来删除工作表。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
if (GridWeb1.WorkSheets.Count > 2) | |
{ | |
// Removing a worksheet using its index | |
GridWeb1.WorkSheets.RemoveAt(1); | |
} |
使用工作表名称
下面的代码显示了如何通过在GridWorksheetCollection的RemoveAt方法中指定工作表名称来删除工作表。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Removing a worksheet using its name | |
if (GridWeb1.WorkSheets["Teachers"] != null) | |
{ | |
GridWeb1.WorkSheets.RemoveAt("Teachers"); | |
} |
还可以使用其引用或实例删除工作表。要这样做,请使用GridWorksheetCollection的Remove方法。这种方法通常被使用。