删除工作表
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 方法。这种方法很常用。