Copy Excel Worksheets in C#

In certain cases, you may need to copy worksheets within an Excel workbook or from one workbook to another. On the other hand, moving worksheets to change their position within a workbook is also required in different scenarios. In order to perform the above-mentioned tasks programmatically, this article shows how to copy Excel worksheets in C#. Furthermore, it also covers how to change the position of a worksheet in an Excel workbook.

C# API to Copy Excel Worksheets - Free Download

In order to copy worksheets in Excel files, we’ll leverage the powerful spreadsheet manipulation capabilities of Aspose.Cells for .NET. The API provides you with a wide range of features to generate and process Excel files from within your .NET applications. You can either download the API’s binaries or install it using NuGet.

PM> Install-Package Aspose.Cells

Copy Excel Worksheets in C#

The following are the steps to copy a worksheet in an Excel workbook using C#.

The following C# code sample shows how to copy an Excel worksheet in a workbook.

C#: Copy Excel Worksheets from One Workbook to Another

Now, let’s have a look at how to copy a worksheet from one Excel workbook to another. The following are the steps to perform this operation.

The following code sample shows how to copy a worksheet from one workbook to another in C#.

Move Excel Worksheet’s Position in C#

There could be the case when you need to rearrange the positions of the worksheets in a workbook. You can do it by moving the worksheets to the desired positions by specifying the index. The following are the steps to move an Excel worksheet from one position to another.

The following code sample shows how to move an Excel worksheet from one position to another using C#.

C# API for Copying Excel Worksheets - Get a Free License

You can try and evaluate Aspose.Cells for .NET for free by requesting a temporary license.

Conclusion

In this article, you have learned how to copy Excel worksheets within a workbook or from one workbook to another using C#. Furthermore, you have seen how to move an Excel worksheet from one position to another within a workbook. You can explore other features of Aspose.Cells for .NET using the documentation. In case you would have any queries, feel free to post to our forum.

See Also