Spread WPF 18
Features / Copy and Paste
In This Topic
    Copy and Paste
    In This Topic

    In Spread for WPF, you can easily copy and paste data within workbooks and worksheets. You can select a cell or a range of cells from one region (source range) in a worksheet and paste it into another region (destination range) within the same or a different worksheet of the same or different workbook.

    Copy and Paste between Worksheets

    To copy data from one cell range to another within the same worksheet or different worksheets in the same workbook, you can use the Copy method of the IRange interface. This method has four overloads, allowing flexibility in how data is copied.

    The following example code uses one of the overloads of the Copy method that accepts the ManipulationOptions enumeration as a parameter.

    Copy Code
    // Copy and paste a range in the same worksheet.
    spreadSheet1.Workbook.ActiveSheet.Cells[0, 0, 2, 2].Copy(3, 3, GrapeCity.Spreadsheet.ManipulationOptions.Values);
    
    Copy Code
    ' Copy and paste a range in the same worksheet.
    spreadSheet1.Workbook.ActiveSheet.Cells(0, 0, 2, 2).Copy(3, 3, GrapeCity.Spreadsheet.ManipulationOptions.Values)
    

    Copy and Paste between Workbooks

    To copy data from one workbook to another within the same workbook set, you can also use the Copy method of the IRange interface. This method allows you to select a range of cells from the source workbook and specify the destination cell in the other workbook where the copied data will be pasted.

    The following example code copies the range A1:C3 from Book1 and pastes it to the cell D4 in Book2. Also, the ManipulationOptions.All enumeration ensures that all features of the copied cells are transferred.

    Copy Code
    // Copy and paste a range to another workbook.
    spreadSheet1.Workbook.Name = "Book1";
    spreadSheet2.Workbook.Name = "Book2";
    spreadSheet1.Workbook.ActiveSheet.Cells["A1:C3"].Copy(spreadSheet2.Workbook.ActiveSheet.Cells["D4"], GrapeCity.Spreadsheet.ManipulationOptions.All);
    
    Copy Code
    ' Copy and paste a range to another workbook.
    spreadSheet1.Workbook.Name = "Book1"
    spreadSheet2.Workbook.Name = "Book2"
    spreadSheet1.Workbook.ActiveSheet.Cells("A1:C3").Copy(spreadSheet2.Workbook.ActiveSheet.Cells("D4"), GrapeCity.Spreadsheet.ManipulationOptions.All)