All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
Row

CellRange.CopyFrom(CellRange, PasteSpecial, Boolean) Method

Copies the source range of cells and pastes the specified part of the copied data into the current cell range.

Namespace: DevExpress.Spreadsheet

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

Declaration

void CopyFrom(
    CellRange source,
    PasteSpecial pasteOptions,
    bool overwriteProtectionOnLockedWorksheet
)

Parameters

Name Type Description
source CellRange

A CellRange object that specifies the cell range to be copied.

pasteOptions PasteSpecial

A PasteSpecial enumeration member that specifies which part of the copied data should be pasted into the current cell range.

overwriteProtectionOnLockedWorksheet Boolean

A Boolean value indicating whether cell protection options (Formatting.Protection) of the source range should be applied to the current range if it is located on the protected worksheet.

Remarks

Relative cell references contained in the source range are automatically adjusted when being copied into the current range. If the source range includes hidden cells (cells that belong to hidden rows or columns), these cells are also copied.

If the current cell range and the specified source cell range are not the same size, data is pasted as follows.

  • If all of the source ranges fit into the current range, the copied data is pasted consecutively to completely fill the current range.

    SpreadsheetControl_CopyPaste_1

  • If all of the source ranges cannot fit into the current range, the copied data is pasted once starting with the top left cell of the current range.

    SpreadsheetControl_CopyPaste_2

  • If the current range contains a single row and all of the source ranges fit into this range width, the copied data is pasted consecutively within the current range width.

    If the current range contains a single row but all of the source ranges cannot fit into this range width, the copied data is pasted once starting with the first cell of the current range.

    SpreadsheetControl_CopyPaste_3

  • If the current range contains a single column and all of the source ranges fit into this range height, the copied data is pasted consecutively within the current range height.

    If the current range contains a single column but all of the source ranges cannot fit into this range height, the copied data is pasted once starting with the first cell of the current range.

    SpreadsheetControl_CopyPaste_4

Example

This example demonstrates how to copy data from one cell to another, and specify which parts of the copied data (for example, value only, formatting information only, borders only, etc.) should be pasted into the destination cell. To do this, call the CellRange.CopyFrom method of the Cell object corresponding to the cell into which you want to copy data from another cell. Pass the source cell object and required member of the PasteSpecial enumerator as parameters.

Worksheet worksheet = workbook.Worksheets[0];
worksheet.Columns["A"].WidthInCharacters = 32;
worksheet.Columns["B"].WidthInCharacters = 20;
Style style = workbook.Styles[BuiltInStyleId.Input];

// Specify the content and formatting for a source cell.
worksheet.Cells["A1"].Value = "Source Cell";

Cell sourceCell = worksheet.Cells["B1"];
sourceCell.Formula = "= PI()";
sourceCell.NumberFormat = "0.0000";
sourceCell.Style = style;
sourceCell.Font.Color = Color.Blue;
sourceCell.Font.Bold = true;
sourceCell.Borders.SetOutsideBorders(Color.Black, BorderLineStyle.Thin);

// Copy all information from the source cell to the "B3" cell. 
worksheet.Cells["A3"].Value = "Copy All";
worksheet.Cells["B3"].CopyFrom(sourceCell);

// Copy only the source cell content (e.g., text, numbers, formula calculated values) to the "B4" cell.
worksheet.Cells["A4"].Value = "Copy Values";
worksheet.Cells["B4"].CopyFrom(sourceCell, PasteSpecial.Values);

// Copy the source cell content (e.g., text, numbers, formula calculated values) 
// and number formats to the "B5" cell.
worksheet.Cells["A5"].Value = "Copy Values and Number Formats";
worksheet.Cells["B5"].CopyFrom(sourceCell, PasteSpecial.Values | PasteSpecial.NumberFormats);

// Copy only the formatting information from the source cell to the "B6" cell.
worksheet.Cells["A6"].Value = "Copy Formats";
worksheet.Cells["B6"].CopyFrom(sourceCell, PasteSpecial.Formats);

// Copy all information from the source cell to the "B7" cell except for border settings.
worksheet.Cells["A7"].Value = "Copy All Except Borders";
worksheet.Cells["B7"].CopyFrom(sourceCell, PasteSpecial.All & ~PasteSpecial.Borders);

// Copy information only about borders from the source cell to the "B8" cell.
worksheet.Cells["A8"].Value = "Copy Borders";
worksheet.Cells["B8"].CopyFrom(sourceCell, PasteSpecial.Borders);
See Also