Skip to main content
Row

Workbook.Merge(IWorkbook[]) Method

Combines the specified workbooks into a new document.

You need a 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.v24.1.dll

NuGet Package: DevExpress.Document.Processor

Declaration

public static Workbook Merge(
    params IWorkbook[] workbooks
)

Parameters

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.

Returns

Type Description
Workbook

A Workbook object that is the resulting workbook.

Remarks

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