# Cut or Copy Cell Ranges

DsExcel allows you to cut or copy a cell or a range of cells from a specific area and paste it into another area within the same worksheet.

## Content

DsExcel .NET provides users with the ability to cut or copy a cell or a range of cells from a specific area and paste it into another area within the same worksheet. You can also choose whether to copy and paste the data in a hidden range in a worksheet. To know more, refer to [Paste or Skip Data in Invisible Range](/document-solutions/dot-net-excel-api/docs/online/Features/ManageWorksheet/RangeOperations/paste-ignore-data-hidden-range).
In order to cut or copy data across multiple sheets, refer to [Cut or Copy Across Sheets](/document-solutions/dot-net-excel-api/docs/online/Features/ManageWorkbook/CutOrCopyAcrossSheets).

## Copy Cell Range

DsExcel allows you to copy a cell or a range of cells in the worksheets by calling [Copy](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.Copy.html) method of [IRange](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.html). To copy a single cell or a range of cells, specify the cell range to be copied, for example **B3:D12**.
DsExcel provides the following different ways to use the Copy method.

| **Example** | **Description** |
| ------- | ----------- |
| Copy(sheet.Range["E5"]) | This method copies data from cell range **B3:D12** and pastes the data to cell **E5** onwards. |
| Copy(sheet.Range["E5:G14"]) | This method copies data from cell range **B3:D12** and pastes the data in cell range **E5:G14**. In case the range of cells copied does not fit into the destination cell range, the data is lost. |

Refer to the following example code in order to copy the cell range in a workbook.

```csharp
// Initialize workbook.
Workbook workbook = new Workbook();

// Fetch default worksheet.
IWorksheet worksheet = workbook.Worksheets[0];

// Set data of PC.
worksheet.Range["A2"].Value = "PC";
worksheet.Range["A4:C4"].Value = new string[]
{
    "Device", "Quantity", "Unit Price"
};
worksheet.Range["A5:C10"].Value = new object[,]
{
    { "T540p", 12, 9850 },
    { "T570", 5, 7460 },
    { "Y460", 6, 5400 },
    { "Y460F", 8, 6240 }
};

// Set style.
worksheet.Range["A2"].RowHeight = 30;
worksheet.Range["A2"].ColumnWidth = 40;
worksheet.Range["A2"].Font.Size = 20;
worksheet.Range["A2"].Font.Bold = true;
worksheet.Range["A4:C4"].Font.Bold = true;
worksheet.Range["A4:C4"].Font.Color = Color.White;
worksheet.Range["A4:C4"].Interior.Color =
Color.LightBlue;
worksheet.Range["A5:C10"].Borders[BordersIndex.InsideHorizontal].Color =
Color.Orange;
worksheet.Range["A5:C10"].Borders[BordersIndex.InsideHorizontal].LineStyle =
BorderLineStyle.DashDot;

// Copy only style and row height from cells A2:C10.
worksheet.Range["H1"].Value = "Copy style & row height from previous cells.";
worksheet.Range["H1"].Font.Color = Color.Red;
worksheet.Range["H1"].Font.Bold = true;
worksheet.Range["A2:C10"].Copy(worksheet.Range["H2"],
new PasteOption { PasteType = PasteType.Formats });

// Set data of mobile devices.
worksheet.Range["H2"].Value = "Mobile";
worksheet.Range["H4:J4"].Value = new string[]
{
    "Device", "Quantity", "Unit Price"
};
worksheet.Range["H5:J10"].Value = new object[,]
{
    { "HW-P30", 20, 4200 },
    { "IPhone-X", 5, 9888 },
    { "IPhone-6s plus", 15, 6880 }
};

// Add new sheet.
IWorksheet worksheet2 = workbook.Worksheets.Add();

// Copy only style of Cell A2:C10 to new sheet.
worksheet.Range["A2:C10"].Copy(worksheet2.Range["A2"],
new PasteOption { PasteType = PasteType.Formats });
worksheet2.Range["A3"].Value = "Copy style from sheet1.";
worksheet2.Range["A3"].Font.Color = Color.Red;
worksheet2.Range["A3"].Font.Bold = true;

// Saving workbook to xlsx.
workbook.Save(@"PasteOptionsEnhancements.xlsx", SaveFileFormat.Xlsx);
```

## Cut Cell Range

DsExcel allows you to cut a cell or a range of cells in the worksheet by calling the [Cut](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.Cut.html) method of the [IRange](/document-solutions/dot-net-excel-api/api/online/DS.Documents.Excel/GrapeCity.Documents.Excel.IRange.html) interface. To cut a cell or the range of cells, specify the cell range to be moved, for example **B3:D12**.
DsExcel provide the following different ways to use Cut method.

| **Example** | **Description** |
| ------- | ----------- |
| Cut(sheet.Range["E5"]) | This method cuts the data from cell range **B3:D12** and pastes the data to cell **E5** onwards. |
| Cut(sheet.Range["E5:G14"]) | This method cuts the data from cell range **B3:D12** and pastes the data in cell range **E5:G14**. In case the range of cells cut does not fit into the destination cell range, the data is lost. |

Refer to the following example code to cut a range of cells in the workbook.

```csharp
// Cut the data of the range of cell
worksheet.Range["B3:D12"].Cut(worksheet.Range["E5"]);
// Or
worksheet.Range["B3:D12"].Cut(worksheet.Range["E5:G14"]);
```

## See Also

[Shapes and Pictures](/document-solutions/dot-net-excel-api/docs/online/Features/WorkWithShape)
[Merge Cells](/document-solutions/dot-net-excel-api/docs/online/Features/ManageWorksheet/RangeOperations/MergeCells)