Back to Devexpress

WorksheetCopyOptions.PasteOptions Property

officefileapi-devexpress-dot-spreadsheet-dot-worksheetcopyoptions.md

latest5.1 KB
Original Source

WorksheetCopyOptions.PasteOptions Property

Specifies the part of data to paste from the copied worksheet into the target worksheet.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public PasteSpecial PasteOptions { get; set; }
vb
Public Property PasteOptions As PasteSpecial

Property Value

TypeDescription
PasteSpecial

One or more Paste Special options.

|

Available values:

NameDescription
Formulas

Pastes cell constant values (for example, text, numbers, and so on) and formulas (but not their calculated values).

| | Values |

Pastes cell values only (including values calculated from formulas, but not formulas themselves).

| | NumberFormats |

Pastes cell number formats only.

| | Borders |

Pastes cell borders only.

| | Formats |

Pastes cell formatting only (font, background, alignment, number format, and borders).

| | Comments |

Pastes cell comments only.

| | ColumnWidths |

Applies column widths only.

| | DataValidations |

Pastes only data validation rules applied to copied cells.

| | Hyperlinks |

Pastes hyperlinks only (without display text).

| | All |

Pastes all cell data (formulas, values, and formatting) except column widths.

|

Example

The following example copies all data from one worksheet to another except for cell comments:

csharp
using DevExpress.Spreadsheet;
// ...

using (Workbook sourceWorkbook = new Workbook())
using (Workbook targetWorkbook = new Workbook())
{
    targetWorkbook.LoadDocument(@"Documents\Book1.xlsx");
    sourceWorkbook.LoadDocument(@"Documents\Book2.xlsx");
    // Add a new worksheet to the destination workbook.
    targetWorkbook.Worksheets.Add("Sheet1_Copy");
    // Specify copy options.
    var copyOptions = new WorksheetCopyOptions()
    {
        // Copy all data except for cell comments. 
        PasteOptions = PasteSpecial.All & ~PasteSpecial.Comments
    };
    // Copy data from "Sheet1" in the source workbook
    // to the newly created worksheet in the destination workbook. 
    targetWorkbook.Worksheets["Sheet1_Copy"].CopyFrom(sourceWorkbook.Worksheets["Sheet1"], copyOptions);
    targetWorkbook.SaveDocument("Result.xlsx");
}
vb
Imports DevExpress.Spreadsheet
' ...

Using sourceWorkbook As New Workbook()
Using targetWorkbook As New Workbook()
  targetWorkbook.LoadDocument("Documents\Book1.xlsx")
  sourceWorkbook.LoadDocument("Documents\Book2.xlsx")
  ' Add a new worksheet to the destination workbook.
  targetWorkbook.Worksheets.Add("Sheet1_Copy")
  ' Specify copy options.
  ' Copy all data except for cell comments. 
  Dim copyOptions As New WorksheetCopyOptions() With {
    .PasteOptions = PasteSpecial.All And Not PasteSpecial.Comments
    }
  ' Copy data from "Sheet1" in the source workbook
  ' to the newly created worksheet in the destination workbook. 
  targetWorkbook.Worksheets("Sheet1_Copy").CopyFrom(sourceWorkbook.Worksheets("Sheet1"), copyOptions)
  targetWorkbook.SaveDocument("Result.xlsx")
End Using
End Using

See Also

WorksheetCopyOptions Class

WorksheetCopyOptions Members

DevExpress.Spreadsheet Namespace