Copy or Move Excel Worksheets

Excel files are used for managing complex data such as departmental budgets or yearly sales reports. There might be situations where you have a ready-made template that you want to use for creating a report. For this, you can create a copy of the template worksheet. You might also need to organize the worksheets to demonstrate the flow of data. For such cases, you can rearrange the worksheets according to your requirements. In light of this, you will learn how to copy and move worksheets programmatically using C++.

C++ API to Copy or Move Excel Worksheets

Aspose.Cells for C++ is a native C++ library that allows you to create, read and update Excel files without requiring Microsoft Excel to be installed. The API also supports copying and moving Excel worksheets. You can either install the API through NuGet or download it directly from the Downloads section.

PM> Install-Package Aspose.Cells.Cpp

Copy Worksheets within an Excel Workbook using C++

The following are the steps to copy worksheets within an Excel workbook.

The following is the sample code to copy a worksheet within an Excel workbook using C++.

Copy Worksheets from One Workbook to Another

Aspose.Cells for C++ also allows you to copy worksheets between two Excel files. The following are the steps to copy a worksheet from one Excel file to another.

The following is the sample code to copy a worksheet from one Excel workbook to another using C++.

Move the Worksheet to a Different Position using C++

The following are the steps to change the position of the worksheet within an Excel Workbook.

The following is the sample code to move the worksheet to a different position within the same workbook using C++.

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to copy worksheets within the same Excel workbook or between different workbooks. Furthermore, you have seen how to change the position of the worksheet within an Excel file. Aspose.Cells for C++ provides many more features for working with Excel files that you can explore by visiting the official documentation. In case of any questions, please feel free to reach us on our free support forum.

See Also