添加或插入工作表

添加工作表

要使用Aspose.Cells.GridDesktop添加工作表,请按照以下步骤进行:

  1. 将Aspose.Cells.GridDesktop控件添加到表单中。
  2. 在GridDesktop控件中调用工作表集合的Add方法。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Adding a worksheet to the Grid
int i = gridDesktop1.Worksheets.Add();
Worksheet sheet = gridDesktop1.Worksheets[i];

Add方法有多个重载版本。例如,使用上述重载版本,可以向Excel文件添加具有默认工作表名称的工作表。使用Add方法的其他重载版本,可以像以下示例中所示定义工作表名称。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Adding a worksheet to the Grid with a specific name
Worksheet sheet1 = gridDesktop1.Worksheets.Add("AddWorksheetWithName");

插入工作表

要使用Aspose.Cells.GridDesktop插入工作表,请按照以下步骤进行:

  1. 在表单中添加 Aspose.Cells.GridDesktop 控件。
  2. 在GridDesktop控件中调用工作表集合的Insert方法。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Inserting a worksheet to Grid at first position of the worksheets collection
gridDesktop1.Worksheets.Insert(0);