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

Workbook.Merge(IWorkbook[]) Method

Combines the specified workbooks into a new document.

You need an active license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this method in production code.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Docs.v20.2.dll


public static Workbook Merge(
    params IWorkbook[] workbooks
Public Shared Function Merge(
    ParamArray workbooks As IWorkbook()
) As Workbook


Name Type Description
workbooks IWorkbook[]

An array of IWorkbook objects that are workbooks to be merged.

If one or more workbooks is null, a System.ArgumentNullException exception occurs.


Type Description

A Workbook object that is the resulting workbook.


Use the Merge method to merge data from multiple workbooks into a new document.

// Add a reference to the DevExpress.Docs.dll assembly.
using DevExpress.Spreadsheet;
// ...

// Create the first workbook.
Workbook book1 = new Workbook();
book1.LoadDocument("Document1.xlsx", DocumentFormat.Xlsx);

// Create the second workbook.
Workbook book2 = new Workbook();
book2.LoadDocument("Document2.xlsx", DocumentFormat.Xlsx);

// Combine two documents into a new document.
Workbook result = Workbook.Merge(book1, book2);

If workbooks being merged contain worksheets with the same name, the added worksheets are automatically renamed and all cell references containing the duplicating worksheet names are updated to use the new names. For instance, if you're trying to merge workbooks containing worksheets named "Sheet1" with a workbook where "Sheet1" already exists, these new worksheets will be renamed in the following way: "Sheet1 (2)", "Sheet1 (3)", etc. To rename a worksheet, use the Worksheet.Name property of the corresponding Worksheet object.

Use the WorkbookExtensions.Append method to add the specified workbooks to an existing workbook that calls the Append method.

See Also