Workbook.Copy

Copy(Workbook, CopyOptions)

Copies another Workbook object.

public void Copy(Workbook source, CopyOptions copyOptions)
ParameterTypeDescription
sourceWorkbookSource Workbook object.
copyOptionsCopyOptionsThe options of copying other workbook.

Remarks

It’s very simple to clone an Excel file.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class WorkbookMethodCopyWithWorkbookCopyOptionsDemo
    {
        public static void Run()
        {
            // Source workbook with macros
            Workbook sourceWorkbook = new Workbook("source_with_macros.xlsm");
            
            // Destination workbook (empty or existing)
            Workbook destWorkbook = new Workbook();
            
            // Configure copy options to keep macros
            CopyOptions options = new CopyOptions();
            options.KeepMacros = true;
            
            // Copy contents from source to destination workbook
            sourceWorkbook.Copy(destWorkbook, options);
            
            // Save the result
            destWorkbook.Save("output_with_macros.xlsm");
        }
    }
}

See Also


Copy(Workbook)

Copies data from a source Workbook object.

public void Copy(Workbook source)
ParameterTypeDescription
sourceWorkbookSource Workbook object.

Examples

using System;
using Aspose.Cells;

namespace AsposeCellsExamples
{
    public class WorkbookMethodCopyWithWorkbookDemo
    {
        public static void Run()
        {
            // Source and output file paths
            string sourceFile = "source.xlsx";
            string outputFile = "output.xlsx";

            // Load the source workbook
            Workbook sourceWorkbook = new Workbook(sourceFile);

            // Create a new workbook and copy contents from source
            Workbook destinationWorkbook = new Workbook();
            destinationWorkbook.Copy(sourceWorkbook);

            // Save the copied workbook
            destinationWorkbook.Save(outputFile);
            
            Console.WriteLine("Workbook copied successfully.");
        }
    }
}

See Also