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 LineCopy 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.
-
1Install IronXL with NuGet Package Manager
-
2Copy and run this code snippet.
workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1") -
3Deploy to test on your live environment
Start using IronXL in your project today with a free trial
Minimal Workflow (5 steps)
- Download the C# library for copying cells
- Load the existing Excel spreadsheet
- Select the range, row, or column that you want to copy
- Invoke the
Copymethod on the selected range - Pass a destination worksheet and position to the
Copymethod
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.
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")What Formatting Is Preserved When Copying?
The Copy method preserves all cell properties including:
Cellvalues 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.

Why Does the Copy Method Take Two Parameters?
The Copy method requires two parameters for precise control:
- Worksheet parameter: Specifies the destination worksheet (same or different within the workbook)
- 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") -
Copy a column (
A):workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1");workSheet.GetColumn(0).Copy(workBook.GetWorkSheet("Sheet1"), "H1") -
Copy a row (
4):workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15");workSheet.GetRow(3).Copy(workBook.GetWorkSheet("Sheet1"), "A15") -
Copy a two-dimensional range (
D6:F8):workSheet["D6:F8"].Copy(workBook.GetWorkSheet("Sheet1"), "H17");workSheet("D6:F8").Copy(workBook.GetWorkSheet("Sheet1"), "H17")
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")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 AGetColumn(1)refers to column BGetRow(0)refers to row 1GetRow(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
Rangeobject 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.

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.
workBook.GetWorksheet("Sheet2")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");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")What Are Common Cross-Worksheet Copy Scenarios?
Cross-worksheet copying frequently serves these scenarios:
- Creating Summary Sheets: Copy key metrics from detail sheets into dashboards
- Template Replication: Copy formatted templates to new worksheets
- Data Consolidation: Gather data from departmental sheets into master sheets
- Report Generation: Copy filtered results to separate reporting worksheets
- 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");Option Strict On
Option Infer On
' Check if worksheet exists before copying
If workBook.GetWorkSheet("TargetSheet") Is Nothing Then
workBook.CreateWorkSheet("TargetSheet")
End If
' Safe copy operation
Dim targetSheet As WorkSheet = workBook.GetWorkSheet("TargetSheet")
sourceSheet("A1:Z100").Copy(targetSheet, "A1")This approach prevents runtime errors and ensures successful copy operations, especially important when automating Excel processes in production environments.
Frequently Asked Questions
How can I copy cells in Excel using C# with IronXL?
You can use IronXL's `Copy` method to duplicate cell content. This method allows you to duplicate cells, ranges, rows, or columns while retaining all data, formulas, and formatting, enabling efficient Excel automation.
What is the significance of the `Copy` method requiring two parameters?
The `Copy` method in IronXL requires two parameters: the worksheet object and the starting position. This ensures precise control over the destination, allowing you to copy within the same sheet or across different sheets, ideal for data consolidation.
What types of formatting are preserved when copying cells with IronXL?
IronXL's `Copy` method preserves all attributes including cell values, formulas, number formats, font styling, borders, background colors, text alignment, and cell protection settings, ensuring the copied content retains its original functionality and appearance.
When should I use a single cell copy versus a range copy in IronXL?
You should use a single cell copy when duplicating individual values, formulas, or specific calculated results. Use range copy for moving entire data tables, multiple related cells, or entire rows or columns while preserving data relationships.
How does IronXL handle copying across different worksheets?
IronXL allows copying across worksheets by accepting a different worksheet object as the first parameter in the `Copy` method. This feature is useful for managing multiple worksheets and creating summary sheets from detailed data.
What happens if the destination range is smaller than the source when copying cells with IronXL?
When the destination range is smaller, IronXL's `Copy` function still accommodates the full source range by overwriting any existing data in the destination area, expanding as needed to fit all copied data.
Why might I choose to copy to a new worksheet rather than an existing one?
Copying to a new worksheet is recommended for creating periodic reports, isolating processed data, building analysis sheets, and generating user-specific views. This ensures data separation and clarity in reporting.
How do row and column references work in IronXL?
IronXL uses zero-based indexing where `GetColumn(0)` refers to column A, and `GetRow(0)` refers to row 1. This aligns with C# array conventions, making it intuitive for developers familiar with standard C# practices.
What are common scenarios for cross-worksheet copying with IronXL?
Cross-worksheet copying in IronXL is commonly used for creating summary sheets, replicating templates to new sheets, consolidating data from multiple sources, generating reports, and performing backup operations of critical data.
How does IronXL handle worksheet naming conflicts during copy operations?
IronXL manages worksheet naming conflicts by allowing you to check for and create target sheets if they don't exist, ensuring safe copy operations without runtime errors, which is crucial for automating Excel processes.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.