This section will demonstrate a nice solution to use C#, VB.NET to move worksheet within workbook. Within this solution, moving worksheet in C#, VB.NET is as easy as ABC. Apply Spire.Xls for .NET in your application, and you can easily move worksheet within Excel using C#, VB.NET.
Spire.XLS for .NET is a professional Excel component for .NET which enables developers/programmers to fast generate, read, write and modify Excel document in their applications. It supports C#, VB.NET, ASP.NET, ASP.NET MVC. Spire.XLS for .NET embed a method - Spire.Xls.WorkShee.MoveWorksheet(int destIndex) in its class design used to move a worksheet to another location in the spreadsheet. The method takes the target worksheet index as a parameter.
Below is the whole code samples used to move worksheet in Excel via C#, VB.NET.
using Spire.Xls; namespace moveSheet { class Program { static void Main(string[] args) { //open Excel Workbook mywbk=new Workbook(); mywbk.LoadFromFile(@"..\test.xls"); // Locate the Worksheet Worksheet mysht=mywbk.Worksheets[0]; //Move Worksheet mysht.MoveWorksheet(2); //Save and Launch mywbk.SaveToFile("result.xls",ExcelVersion.Version97to2003); System.Diagnostics.Process.Start("result.xls"); } } }
Imports Spire.Xls Namespace moveSheet Class Program Private Shared Sub Main(args As String()) 'open Excel Dim mywbk As New Workbook() mywbk.LoadFromFile("..\test.xls") ' Locate the Worksheet Dim mysht As Worksheet = mywbk.Worksheets(0) 'Move Worksheet mysht.MoveWorksheet(2) 'Save and Launch mywbk.SaveToFile("result.xls",ExcelVersion.Version97to2003) System.Diagnostics.Process.Start("result.xls") End Sub End Class End Namespace