.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

How to: Copy Worksheets between Workbooks

  • 2 minutes to read

You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.

This example demonstrates how to add an existing worksheet to a new workbook. To do this, access a Worksheet object that specifies a worksheet into which you want to copy another worksheet and call its Worksheet.CopyFrom method with the source worksheet object passed as a parameter.

// Create a source workbook.
Workbook sourceWorkbook = new Workbook();

// Add a new worksheet.

// Modify the second worksheet of the source workbook to be copied.
sourceWorkbook.Worksheets[1].Cells["A1"].Value = "A worksheet to be copied";
sourceWorkbook.Worksheets[1].Cells["A1"].Font.Color = Color.ForestGreen;

// Copy the second worksheet of the source workbook into the first worksheet of another workbook.
See Also