在工作簿内移动工作表
Contents
[
Hide
]
Aspose.Cells提供了一个方法Aspose.Cells.Worksheet.MoveTo(),用于将工作表移动到电子表格中的另一个位置。该方法以目标工作表索引作为参数。
以下示例显示了如何将工作表移动到工作簿内的另一个位置。
string FilePath = @"..\..\..\Sample Files\";
string FileName = FilePath + "Move Worksheet.xlsx";
//Open an existing excel file.
Workbook wb = new Workbook(FileName);
//Create a Worksheets object with reference to
//the sheets of the Workbook.
WorksheetCollection sheets = wb.Worksheets;
//Get the first worksheet.
Worksheet worksheet = sheets[0];
string test = worksheet.Name;
//Move the first sheet to the third position in the workbook.
worksheet.MoveTo(2);
//Save the excel file.
wb.Save(FileName);