How to Copy Cells using IronXL

How to Copy Cells in C# with IronXL

IronXL enables copying cells, ranges, rows, or columns in Excel spreadsheets using a single Copy method that preserves all formatting and styling while duplicating data between any locations or worksheets.

The "Copy cell" feature duplicates cell contents and pastes them into other cells. It replicates data, formulas, formatting, and other attributes within the worksheet. Whether creating spreadsheets from scratch or loading existing Excel files, the copy functionality is essential for efficient data manipulation.

Quickstart: Copy a Column or Range in One Line

Copy entire ranges—single cells, rows, columns, or blocks—from one sheet to another using one method call. The Copy function retains styling and formatting while making Excel automation fast and simple.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronXL with NuGet Package Manager

    PM > Install-Package IronXL.Excel

  2. Copy and run this code snippet.

    workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");
  3. Deploy to test on your live environment

    Start using IronXL in your project today with a free trial
    arrow pointer


How Do I Copy a Single Cell in Excel?

To copy a selected cell's content, use the Copy method. Pass the worksheet object as the first parameter and the starting position as the second parameter. The Copy method retains all styling including font and size, background patterns and colors, and borders and alignment.

: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");
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");
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");
$vbLabelText   $csharpLabel

What Formatting Is Preserved When Copying?

The Copy method preserves all cell properties including:

  • Cell values and formulas
  • Number formats (currency, percentage, dates)
  • Font styling (typeface, size, bold, italic, color)
  • Cell borders and background colors
  • Text alignment (horizontal and vertical)
  • Cell protection settings

This comprehensive preservation ensures copied cells maintain their original appearance and functionality, similar to using Ctrl+C and Ctrl+V in Microsoft Excel.

Spreadsheet showing cell A1 selected with arrow pointing to cell B3 containing copied value, demonstrating single cell copy

Why Does the Copy Method Take Two Parameters?

The Copy method requires two parameters for precise control:

  1. Worksheet parameter: Specifies the destination worksheet (same or different within the workbook)
  2. Address parameter: Defines the starting cell position for pasted content

This design allows flexible copying within the same sheet or across different sheets, ideal for creating summary reports or consolidating data from multiple sources.

When Should I Use Single Cell Copy vs Range Copy?

Choose single cell copy when:

  • Duplicating individual values or formulas
  • Copying header cells or labels
  • Replicating specific calculated results
  • Working with summary values

Use range copy when:

  • Moving entire data tables
  • Duplicating multiple related cells
  • Copying complete rows or columns
  • Preserving data relationships

How Can I Copy Multiple Cells or Ranges?

Like the Clear method, Copy is available in the Range class, allowing execution on any range size. When selecting ranges, IronXL provides flexible copying options:

  • Copy a single cell (C10):

    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");
    $vbLabelText   $csharpLabel
  • Copy a row (4):

    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");
    $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");
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");
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");
$vbLabelText   $csharpLabel

What Happens When the Destination Range Is Too Small?

IronXL automatically handles size differences:

  • The destination parameter specifies only the top-left starting cell
  • The entire source range copies regardless of destination size
  • Existing data in the destination area gets overwritten
  • The copy operation expands to accommodate all source data

For example, copying a 3x3 range to cell B1 populates cells B1:D3, overwriting any existing content.

How Do Row and Column References Work?

IronXL uses zero-based indexing for rows and columns with GetRow() and GetColumn() methods:

  • GetColumn(0) refers to column A
  • GetColumn(1) refers to column B
  • GetRow(0) refers to row 1
  • GetRow(3) refers to row 4

This indexing aligns with standard C# array conventions.

Why Use GetColumn() and GetRow() Methods?

GetColumn() and GetRow() methods offer:

  • Performance: More efficient for entire rows or columns
  • Clarity: Makes code intent clearer
  • Flexibility: Returns a Range object supporting all range operations
  • Convenience: No need to calculate end cells for full selections

These methods excel when creating reports requiring full column copies or when duplicating row templates.

Excel copy operations showing arrows from source ranges A1:F10 to destination cells with highlighted copied data

How Do I Copy Cells Between Different Worksheets?

The first parameter accepts a worksheet object, enabling copy and paste across different worksheets. Pass a different worksheet object as the first parameter. This functionality proves essential when managing multiple worksheets or creating summary sheets from detailed data.

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

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

WorkBook workBook = WorkBook.Load("multisheet.xlsx");
WorkSheet sheet1 = workBook.GetWorkSheet("Sheet1");
WorkSheet sheet2 = workBook.GetWorkSheet("Sheet2");

// Copy entire data range from Sheet1 to Sheet2
sheet1["A1:D10"].Copy(sheet2, "A1");

// Copy with formulas intact
sheet1["E1:E10"].Copy(sheet2, "F1");

// Copy formatting from template sheet
WorkSheet templateSheet = workBook.GetWorkSheet("Template");
templateSheet["A1:Z1"].Copy(sheet2, "A15");

workBook.SaveAs("crossSheetCopy.xlsx");
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");
using IronXL;

WorkBook workBook = WorkBook.Load("multisheet.xlsx");
WorkSheet sheet1 = workBook.GetWorkSheet("Sheet1");
WorkSheet sheet2 = workBook.GetWorkSheet("Sheet2");

// Copy entire data range from Sheet1 to Sheet2
sheet1["A1:D10"].Copy(sheet2, "A1");

// Copy with formulas intact
sheet1["E1:E10"].Copy(sheet2, "F1");

// Copy formatting from template sheet
WorkSheet templateSheet = workBook.GetWorkSheet("Template");
templateSheet["A1:Z1"].Copy(sheet2, "A15");

workBook.SaveAs("crossSheetCopy.xlsx");
$vbLabelText   $csharpLabel

What Are Common Cross-Worksheet Copy Scenarios?

Cross-worksheet copying frequently serves these scenarios:

  1. Creating Summary Sheets: Copy key metrics from detail sheets into dashboards
  2. Template Replication: Copy formatted templates to new worksheets
  3. Data Consolidation: Gather data from departmental sheets into master sheets
  4. Report Generation: Copy filtered results to separate reporting worksheets
  5. Backup Operations: Duplicate critical data to backup sheets

When working with formulas that reference other cells, IronXL automatically adjusts relative references based on the new location while maintaining absolute references.

When Should I Copy to a New Worksheet vs Existing?

Copy to a new worksheet when:

  • Creating periodic reports (daily, weekly, monthly)
  • Isolating processed data from raw data
  • Building analysis worksheets from source data
  • Generating user-specific data views

Copy to an existing worksheet when:

  • Appending data to ongoing logs
  • Updating dashboard sections
  • Consolidating multiple data sources
  • Maintaining historical records

For complex scenarios involving multiple sheets, consider using IronXL's ability to work with DataSets and DataTables for sophisticated data manipulation.

How to Handle Worksheet Naming Conflicts?

Ensure proper worksheet management when copying between worksheets:

// Check if worksheet exists before copying
if (workBook.GetWorkSheet("TargetSheet") == null)
{
    workBook.CreateWorkSheet("TargetSheet");
}

// Safe copy operation
WorkSheet targetSheet = workBook.GetWorkSheet("TargetSheet");
sourceSheet["A1:Z100"].Copy(targetSheet, "A1");
// Check if worksheet exists before copying
if (workBook.GetWorkSheet("TargetSheet") == null)
{
    workBook.CreateWorkSheet("TargetSheet");
}

// Safe copy operation
WorkSheet targetSheet = workBook.GetWorkSheet("TargetSheet");
sourceSheet["A1:Z100"].Copy(targetSheet, "A1");
$vbLabelText   $csharpLabel

This approach prevents runtime errors and ensures successful copy operations, especially important when automating Excel processes in production environments.

Frequently Asked Questions

How do I copy a single cell in Excel using C#?

With IronXL, you can copy a single cell using the Copy method. Simply select the cell you want to copy (e.g., workSheet["A1"]) and call the Copy method, passing the destination worksheet and target cell address as parameters. IronXL preserves all formatting including fonts, colors, borders, and formulas during the copy operation.

What formatting is preserved when copying cells?

IronXL's Copy method preserves all cell properties including cell values and formulas, number formats (currency, percentage, dates), font styling (typeface, size, bold, italic, color), cell borders and background colors, text alignment (horizontal and vertical), and cell protection settings. This ensures copied cells maintain their original appearance and functionality.

Can I copy entire columns or ranges at once?

Yes, IronXL allows you to copy entire columns, rows, or ranges in a single operation. You can use methods like GetColumn(0).Copy() to copy an entire column or select a range of cells to copy multiple cells at once. The Copy method works with any selection size, from single cells to entire worksheets.

How do I copy cells between different worksheets?

IronXL makes it easy to copy cells between worksheets. When using the Copy method, specify the destination worksheet as the first parameter (e.g., workBook.GetWorkSheet("Sheet2")) and the target cell address as the second parameter. This allows you to copy data across different sheets within the same workbook.

What are the minimum steps required to copy cells in Excel?

With IronXL, copying cells requires just 5 steps: 1) Download the IronXL C# library, 2) Load your existing Excel spreadsheet, 3) Select the range, row, or column you want to copy, 4) Invoke the Copy method on the selected range, and 5) Pass a destination worksheet and position to the Copy method. The entire operation can be done in a single line of code.

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.
Ready to Get Started?
Nuget Downloads 1,780,288 | Version: 2025.12 just released