Get Range with External Links using Node.js via C++
Contents
[
Hide
]
Get Range with External Links
A lot of times Excel files access data from other Excel files using external links. Aspose.Cells for Node.js via C++ provides the option to retrieve these external links by using the Name.getReferredAreas(boolean) method. The Name.getReferredAreas(boolean) method returns an array of type ReferredArea. The ReferredArea class provides an ReferredArea.getExternalFileName() property which returns the name of the external file. The ReferredArea class exposes the following members.
- ReferredArea.getEndColumn(): The end column of the area
- ReferredArea.getEndRow(): The end row of the area
- ReferredArea.getExternalFileName(): Get the external file name if this is an external reference
- ReferredArea.isArea(): Indicates whether this is an area
- ReferredArea.isExternalLink(): Indicates whether this is an external link
- ReferredArea.getSheetName(): Indicates which sheet this reference is in
- ReferredArea.getStartColumn(): The start column of the area
- ReferredArea.getStartRow(): The start row of the area
The sample code given below demonstrates the use of Name.getReferredAreas(boolean) method to get Ranges with external links.
Sample Code
try
{
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// Source directory
const sourceDir = path.join(__dirname, "data");
// Load source Excel file
const filePath = path.join(sourceDir, "SampleExternalReferences.xlsx");
const workbook = new AsposeCells.Workbook(filePath);
console.log(filePath);
const names = workbook.getWorksheets().getNames();
const namesCount = names.getCount();
for (let i = 0; i < namesCount; i++)
{
const namedRange = names.get(i);
const referredAreas = namedRange.getReferredAreas(true);
if (referredAreas)
{
referredAreas.forEach(referredArea => {
// Print the data in Referred Area
console.log("IsExternalLink: " + referredArea.isExternalLink());
console.log("IsArea: " + referredArea.isArea());
console.log("SheetName: " + referredArea.getSheetName());
console.log("ExternalFileName: " + referredArea.getExternalFileName());
console.log("StartColumn: " + referredArea.getStartColumn());
console.log("StartRow: " + referredArea.getStartRow());
console.log("EndColumn: " + referredArea.getEndColumn());
console.log("EndRow: " + referredArea.getEndRow());