Move Worksheet in WPF

It is not an easy task for WPF developers moving worksheet to another location in a workbook, as calculations or charts that are based on worksheet data might become inaccurate if you move the worksheet in WPF application. Here presents a solution that saves you from these worries. Apply Spire.Xls for WPF in your application,  and you easily can move worksheet in your WPF application.

Spire.XLS for WPF is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document in WPF applications. 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 and lead no inaccuracy on these calculations or charts.

Now Feel free to download Spire.XLS for WPF and use  the code samples below to move worksheet in WPF application.

[C#]
using Spire.Xls;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            //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");
            System.Diagnostics.Process.Start("result.xls");

        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports System.Windows

Namespace WpfApplication1
	Public Partial Class MainWindow
		Inherits Window
		Public Sub New()
			InitializeComponent()
		End Sub
		Private Sub button2_Click(sender As Object, e As RoutedEventArgs)
			'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")
			System.Diagnostics.Process.Start("result.xls")

		End Sub
	End Class
End Namespace