Copy and Move Worksheets Within and Between Workbooks with Golang via C++

Copying and Moving Worksheets

Copying a Worksheet within a Workbook

The initial steps are the same for all examples:

  1. Create two workbooks with some data in Microsoft Excel. For the purposes of this example, we created two new workbooks in Microsoft Excel and input some data into the worksheets:

    • FirstWorkbook.xlsx (3 worksheets)
    • SecondWorkbook.xlsx (1 worksheet)
  2. Download and install Aspose.Cells:

    1. Download Aspose.Cells for C++
    2. Install it on your development computer
  3. Create a project:

    1. Create a new C++ project in your preferred IDE
  4. Add references:

    1. Add Aspose.Cells for C++ library to your project
  5. Copy the worksheet within a workbook The first example copies the first worksheet (Copy) within FirstWorkbook.xlsx.

When executing the code, the worksheet named Copy is copied within FirstWorkbook.xlsx with the name Last Sheet.

Moving a Worksheet within a Workbook

The code below shows how to move a worksheet from one position in a workbook to another. Executing the code moves the worksheet called Move from index 1 to index 2 in FirstWorkbook.xlsx.

Copying a Worksheet between Workbooks

Executing the code copies the worksheet named Copy to SecondWorkbook.xlsx with the name Sheet2.

Moving a Worksheet between Workbooks

Executing the code moves the worksheet named Move from FirstWorkbook.xlsx to SecondWorkbook.xlsx with the name Sheet3.