如何使用 IronXL 复制单元格

How to Copy Cells

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Copy a Column or Range in One Line

With IronXL, developers can copy entire ranges—whether it's a single cell, row, column or block—from one sheet to another using just one method call. The Copy function retains styling and formatting while making Excel automation easy and fast.

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


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

请注意The 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.

请注意In 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

常见问题解答

如何在C#中高效复制单元格内容?

要在C#中高效复制单元格内容,使用IronXL的Copy方法。此方法允许您在同一工作表或跨多个工作表中复制数据、公式和样式。

如何在C#中复制单个单元格?

您可以使用IronXL在C#中通过调用单元格上的Copy方法来复制单个单元格,指定目标工作表和位置。该方法保留任何现有的单元格样式。

在C#库中复制列的过程是什么?

要使用C#中的IronXL复制列,使用GetColumn方法选择列,然后应用Copy方法指定目标工作表和位置。

如何在C#中复制一行数据?

要在C#中复制行,使用IronXL的GetRow方法选择行,然后使用Copy方法定义目标工作表和起始位置。

在C#中是否可以复制特定的单元格范围?

是的,IronXL允许您使用Copy方法复制特定的单元格范围。您需要指定单元格范围和目标工作表的起始位置。

我可以在C#中在工作表之间传输单元格吗?

是的,IronXL支持在工作表之间传输单元格。您可以使用Copy方法并将目标工作表对象作为第一个参数传递。

在C#中复制单元格时格式会被保留吗?

IronXL的Copy方法在复制单元格时保留单元格格式和样式,以便进行一致的数据复制。

使用C#库复制单元格需要哪些步骤?

要使用IronXL复制单元格,从NuGet下载库,加载您的Excel电子表格,选择所需的范围、行或列,并使用Copy方法指定目标。

如何指定复制的数据应放置在工作表的何处?

在IronXL中,使用Copy方法的第二个参数指定复制数据的目标位置,该参数定义目标工作表中的起始地址。

在C#应用程序中可以自动化单元格复制吗?

是的,使用IronXL,您可以通过利用Copy方法以及库提供的其他自动化功能来自动化C#应用程序中的单元格复制。

Chaknith Bin
软件工程师
Chaknith 在 IronXL 和 IronBarcode 工作。他在 C# 和 .NET 方面有着深厚的专业知识,帮助改进软件并支持客户。他从用户互动中获得的见解有助于更好的产品、文档和整体体验。
准备开始了吗?
Nuget 下载 1,686,155 | 版本: 2025.11 刚刚发布