How to Copy Cells

The "Copy cell" feature allows you to duplicate the contents of a cell and paste them into one or more other cells. It is a convenient way to replicate data, formulas, formatting, or other attributes within the worksheet.

Additionally, the Copy method also retains styling, enabling efficient and accurate data replication within a single or multiple worksheets using IronXL.


Get started with IronXL

Start using IronXL in your project today with a free trial.

First Step:
green arrow pointer


Copy a Single Cell Example

To copy the content of a selected cell, you can use the Copy method. Pass the worksheet object as the first parameter and the starting position as the second parameter. The Copy method also retains any styling that the cell contains.

:path=/static-assets/excel/content-code-examples/how-to/copy-cells-copy-single-cell.cs
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Copy cell content
workSheet["A1"].Copy(workBook.GetWorkSheet("Sheet1"), "B3");

workBook.SaveAs("copySingleCell.xlsx");
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Copy cell content
workSheet("A1").Copy(workBook.GetWorkSheet("Sheet1"), "B3")

workBook.SaveAs("copySingleCell.xlsx")
$vbLabelText   $csharpLabel

Output Spreadsheet

Copy Single Cell

Copy Cell Range Example

Similar to the Clear method, this method is also available in the Range class, allowing you to execute it on any range, regardless of its size. Here are some examples:

  • Copy a single cell (C10):

    workSheet["C10"].Copy(workBook.GetWorkSheet("Sheet1"), "B13");
    workSheet["C10"].Copy(workBook.GetWorkSheet("Sheet1"), "B13");
    workSheet("C10").Copy(workBook.GetWorkSheet("Sheet1"), "B13")
    $vbLabelText   $csharpLabel
  • Copy a column (A):

    workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");
    workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");
    workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1")
    $vbLabelText   $csharpLabel
  • Copy a row (4):

    workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15");
    workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15");
    workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15")
    $vbLabelText   $csharpLabel
  • Copy a two-dimensional range (D6:F8):

    workSheet["D6:F8"].Copy(workBook.GetWorkSheet("Sheet1"), "H17");
    workSheet["D6:F8"].Copy(workBook.GetWorkSheet("Sheet1"), "H17");
    workSheet("D6:F8").Copy(workBook.GetWorkSheet("Sheet1"), "H17")
    $vbLabelText   $csharpLabel

Please noteThe second parameter accepts an address location that marks the starting point of data entry. The copied data will start from that address and spread rightward and downward.

:path=/static-assets/excel/content-code-examples/how-to/copy-cells-copy-cell-range.cs
using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Copy a single cell(C10)
workSheet["C10"].Copy(workBook.GetWorkSheet("Sheet1"), "B13");

// Copy a column(A)
workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");

// Copy a row(4)
workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15");

// Copy a two-dimensional range(D6:F8)
workSheet["D6:F8"].Copy(workBook.GetWorkSheet("Sheet1"), "H17");

workBook.SaveAs("copyCellRange.xlsx");
Imports IronXL

Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Copy a single cell(C10)
workSheet("C10").Copy(workBook.GetWorkSheet("Sheet1"), "B13")

' Copy a column(A)
workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1")

' Copy a row(4)
workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15")

' Copy a two-dimensional range(D6:F8)
workSheet("D6:F8").Copy(workBook.GetWorkSheet("Sheet1"), "H17")

workBook.SaveAs("copyCellRange.xlsx")
$vbLabelText   $csharpLabel

Output Spreadsheet

Copy Cell Range

Copy Cell Across Worksheet Example

Since the first parameter accepts a worksheet object, it is possible to copy and paste a cell range across different worksheets. Simply pass a different worksheet object as the first parameter.

Please noteIn the following example, the first parameter of the Copy method is the "Sheet2" worksheet: workBook.GetWorksheet("Sheet2")

// Example Code: Copy cells across different worksheets in IronXL

using IronXL;

:path=/static-assets/excel/content-code-examples/how-to/copy-cells-copy-to-other-worksheet.cs
// Example Code: Copy cells across different worksheets in IronXL

using IronXL;

using IronXL;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.GetWorkSheet("Sheet1");

// Copy cell content
workSheet["A1"].Copy(workBook.GetWorkSheet("Sheet2"), "B3");

workBook.SaveAs("copyAcrossWorksheet.xlsx");
' Example Code: Copy cells across different worksheets in IronXL

Imports IronXL


Private workBook As WorkBook = WorkBook.Load("sample.xlsx")
Private workSheet As WorkSheet = workBook.GetWorkSheet("Sheet1")

' Copy cell content
workSheet("A1").Copy(workBook.GetWorkSheet("Sheet2"), "B3")

workBook.SaveAs("copyAcrossWorksheet.xlsx")
$vbLabelText   $csharpLabel

Frequently Asked Questions

How do I copy cell content efficiently in C#?

To copy cell content efficiently in C#, use IronXL's Copy method. This method allows you to duplicate data, formulas, and styling within the same worksheet or across multiple worksheets.

How can I copy a single cell in C#?

You can copy a single cell in C# using IronXL by calling the Copy method on the cell, specifying the destination worksheet and position. The method retains any existing cell styling.

What is the procedure to copy a column in a C# library?

To copy a column using IronXL in C#, use the GetColumn method to select the column, then apply the Copy method to specify the destination worksheet and position.

How can I copy a row of data in C#?

To copy a row in C#, use IronXL's GetRow method to select the row, followed by the Copy method to define the destination worksheet and starting position.

Is it possible to copy a specific range of cells in C#?

Yes, IronXL allows you to copy a specific range of cells using the Copy method. You need to specify the cell range and destination worksheet with a starting position.

Can I transfer cells between worksheets in C#?

Yes, IronXL supports transferring cells between worksheets. You can use the Copy method and pass the destination worksheet object as the first parameter.

Will the formatting be preserved when copying cells in C#?

IronXL's Copy method preserves the cell formatting and styling when you copy cells, allowing for consistent data replication.

What steps are necessary to copy cells using a C# library?

To copy cells using IronXL, download the library from NuGet, load your Excel spreadsheet, select the desired range, row, or column, and use the Copy method to specify the destination.

How do I specify where the copied data should be placed in a worksheet?

In IronXL, specify the destination position for the copied data using the second parameter of the Copy method, which defines the starting address in the target worksheet.

Can cell copying be automated in C# applications?

Yes, using IronXL, you can automate cell copying in C# applications by leveraging the Copy method alongside other automation functionalities provided by the library.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.