Skip to main content
A newer version of this page is available. .

How to: Copy Worksheets between Workbooks

  • 2 minutes to read

Important

You require 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.
sourceWorkbook.Worksheets.Add();

// 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.
workbook.Worksheets[0].CopyFrom(sourceWorkbook.Worksheets[1]);
See Also