Remove Worksheets
Contents
[
Hide
]
This topic provides information about how to remove worksheets from Microsoft Excel files using the Aspose.Cells.GridWeb API.It is possible to either remove a worksheet by specifying its sheet index or name.
Removing a Worksheet
Using Sheet Index
The code below shows how to remove a worksheet by specifying its sheet index in the GridWorksheetCollection’s RemoveAt method.
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); | |
} |
Using Sheet Name
The code below shows how to remove a worksheet by specifying its sheet name in the GridWorksheetCollection’s RemoveAt method.
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"); | |
} |
It is also possible to remove a worksheet using its reference or instance. To do so, use the GridWorksheetCollection’s Remove method. This approach is commonly used.