Mover hojas de trabajo dentro del libro de trabajo

Aspose.Cells proporciona un método, Aspose.Cells.Worksheet.MoveTo(), que se usa para mover una hoja de trabajo a otra ubicación en la hoja de cálculo. El método toma el índice de la hoja de cálculo de destino como parámetro.

El siguiente ejemplo muestra cómo mover una hoja de trabajo a otra ubicación dentro del libro de trabajo.

 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);

Descargar código de muestra