Workbook.ExternalWorkbooks Property
Provides access to the collection of source workbooks used for creating external references in the current workbook.
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use this property in production code.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Docs.v24.2.dll
NuGet Package: DevExpress.Document.Processor
Declaration
Property Value
Type | Description |
---|---|
ExternalWorkbookCollection | An ExternalWorkbookCollection object. |
Remarks
To use cell references and defined names contained in another workbook, you should add a workbook to the ExternalWorkbooks collection.
The following code snippet creates a workbook, populates it with random data by importing a data table and adds to the collection of external workbooks.
Workbook externalWorkbook = new Workbook();
externalWorkbook.Options.Save.CurrentFileName = "ExternalDocument.xlsx";
// Check whether the external workbook is already referenced.
foreach (IWorkbook item in myWorkbook.ExternalWorkbooks)
{
if (item.Options.Save.CurrentFileName == externalWorkbook.Options.Save.CurrentFileName)
return;
}
externalWorkbook.Worksheets[0].Import(CreateDataTable(10), false, 0, 0);
externalWorkbook.SaveDocument("ExternalDocument.xlsx");
myWorkbook.ExternalWorkbooks.Add(externalWorkbook);
Subsequently you can reference this workbook from the current workbook, as illustrated in the code below.
if (myWorkbook.ExternalWorkbooks.Count == 0)
{
return;
}
IWorkbook extWorkbook = (IWorkbook)myWorkbook.ExternalWorkbooks[0];
string extWorkbookName = extWorkbook.Options.Save.CurrentFileName;
string sFormula = String.Format("=[{0}]Sheet1!A1", extWorkbookName);
myWorkbook.Worksheets[0].Cells["A1"].Formula = sFormula;
myWorkbook.SaveDocument("Test.xlsx");
System.Diagnostics.Process.Start("Test.xlsx");
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ExternalWorkbooks property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.