添加或插入工作表

添加工作表

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

  1. 将 Aspose.Cells.GridDesktop 控件添加到窗体。
  2. 在 GridDesktop 控件中调用 Worksheet 集合的 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 控件中调用 Worksheets 集合的 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);