Skip to main content
All docs
.NET Framework 4.5.2+

WorksheetCopyOptions Class

Allows you to define copy options when you copy data from one worksheet to another.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v23.1.Core.dll


public class WorksheetCopyOptions


Use the Worksheet.CopyFrom method copy data from one worksheet to another. Create a WorksheetCopyOptions instance and pass it to this method to specify copy options. The following options are available:

Option Description
PasteOptions Specifies the part of data to paste from the copied worksheet into the target worksheet.
InvalidFormulaReplacementMode Specifies how to replace copied formulas if they contain references to worksheets that do not exist in the destination workbook.
SheetMappings Allows you to specify mappings between worksheet names in the source and destination workbooks. Use this property to replace external cell references in formulas with references to sheets in the destination workbook.
OverwriteProtectionOnLockedWorksheet Specifies whether to apply cell protection options of the source worksheet to cells in the protected destination worksheet.


The example below demonstrates how to copy all worksheets from one workbook to another. Sheets are copied with their original names. The SheetMappings property is used to update formula references so they point to worksheets in the destination workbook.

using DevExpress.Spreadsheet;
using System.Linq;
// ...

using (Workbook sourceWorkbook = new Workbook())
using (Workbook targetWorkbook = new Workbook())
    var copyOptions = new WorksheetCopyOptions();
    // Specify mappings between worksheets in the source
    // and destination workbooks. Sheets are copied 
    // with their original names.
    copyOptions.SheetMappings = sourceWorkbook.Sheets.ToDictionary(
        sheet => sheet.Name, sheet => sheet.Name);
    // Copy all worksheets from the source workbook
    // to the target workbook.
    CopySheetsToWorkbook(sourceWorkbook, targetWorkbook, copyOptions);

// ...

private static void CopySheetsToWorkbook(Workbook sourceWorkbook, 
    Workbook targetWorkbook, WorksheetCopyOptions options)
    foreach (var sheet in sourceWorkbook.Worksheets)
        string sheetName = sheet.Name;
        if (!targetWorkbook.Worksheets.Contains(sheetName))
        targetWorkbook.Worksheets[sheetName].CopyFrom(sheet, options);


See Also