添加工作表
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控件添加具有特定名称的工作表,而不使用默认的命名方案,可调用Add方法的重载版本,该重载版本接受指定的SheetName。例如,下面的示例添加了名为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 的实例。