添加工作表
Contents
[
Hide
]
工作表是 Aspose.Cells.GridWeb 的组成部分。所有数据都以工作表的形式进行管理和存储。 Aspose.Cells.GridWeb 允许开发人员向 Aspose.Cells.GridWeb 控件添加一个或多个工作表。本主题展示了将工作表添加到 Aspose.Cells.GridWeb 的简单方法。
添加工作表
不指定工作表名称
向 Aspose.Cells.GridWeb 添加工作表的最简单方法是在 GridWeb 控件中调用 GridWorksheetCollection 集合的 Add 方法。这将创建使用默认名称(即 Sheet1、Sheet2、Sheet3 等)的工作表并将它们添加到 GridWeb 控件。
输出:具有默认名称的工作表已添加到 GridWeb
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 | |
// Adding a worksheet to GridWeb without specifying name | |
int sheetIndex = GridWeb1.WorkSheets.Add(); | |
GridWorksheet sheet = GridWeb1.WorkSheets[sheetIndex]; | |
Label1.Text = sheet.Name + " worksheet is added at index " + sheetIndex + ". <br/>"; |
Add 方法返回新工作表的索引,该索引可用于访问此工作表的实例。有关如何访问工作表的更多详细信息,请阅读访问工作表.
具有指定的工作表名称
若要将具有特定名称的工作表添加到 GridWeb 控件而不是使用默认命名方案,请调用采用指定 SheetName 的 Add 方法的重载版本。例如,下面的示例添加了一个名为 Invoice 的工作表。
输出:具有指定名称的工作表已添加到 GridWeb
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 | |
//Adding a worksheet to GridWeb with a specified name | |
if (GridWeb1.WorkSheets["Teachers"] == null) | |
{ | |
GridWorksheet sheet1 = GridWeb1.WorkSheets.Add("Teachers"); | |
Label1.Text += sheet1.Name + " worksheet is added at index " + sheet1.Index + ". <br/>"; | |
} |
接受工作表名称作为字符串的 Add 方法返回 GridWorksheet 的一个实例。