WorksheetCopyOptions.CopyDefinedNames Property
Specifies which defined names should be copied in case they contain references to non-existent worksheets.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v25.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Property Value
| Type | Description |
|---|---|
| CopyDefinedNamesMode | An enumeration value that indicates the defined name type to copy. |
Available values:
| Name | Description |
|---|---|
| All | Copy all defined names. |
| Referenced | Copy defined names that reference existing worksheets. |
Remarks
When you copy a worksheet from one workbook to another, the source worksheet may have defined names. These names might reference worksheets that do not exist in the target workbook. Use the CopyDefinedNames property to specify whether to copy these defined names to the target workbook. Set the property to Referenced to exclude references to non-existent worksheets.
The following code snippet specifies copy options and copies a worksheet between workbooks:
using DevExpress.Spreadsheet;
//...
using (Workbook sourceWorkbook = new Workbook())
using (Workbook targetWorkbook = new Workbook())
{
targetWorkbook.LoadDocument(@"Documents\Book1.xlsx");
sourceWorkbook.LoadDocument(@"Documents\Book2.xlsx");
var copyOptions = new WorksheetCopyOptions();
copyOptions.CopyDefinedNames = CopyDefinedNamesMode.Referenced;
targetWorkbook.Worksheets[0].CopyFrom(sourceWorkbook.Worksheets[0], copyOptions);
targetWorkbook.Calculate();
targetWorkbook.SaveDocument("MergedDocument.xlsx");
}