Filter Defined Names while loading Workbook with Node.js via C++
Possible Usage Scenarios
Aspose.Cells allows you to filter or remove defined names present inside the workbook. Please use LoadDataFilterOptions.DefinedNames to load defined names and use LoadDataFilterOptions.DefinedNames to remove them while loading the workbook. Please note, if you remove defined names, then formulas inside the workbook may break.
Filter Defined Names while loading Workbook
The following sample code loads the sample Excel file which has a formula in cell C1 containing the defined names i.e. =SUM(MyName1, MyName2). Since we are using LoadDataFilterOptions.DefinedNames to remove the defined names while loading the workbook, the formula in cell C1 in the output Excel file breaks and you see #NAME? instead. Please see the following screenshot that shows the effect of the code on the sample Excel file.
Sample Code
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sampleFilterDefinedNamesWhileLoadingWorkbook.xlsx");
// Specify the load options
let opts = new AsposeCells.LoadOptions();
// We do not want to load defined names
opts.setLoadFilter(new AsposeCells.LoadFilter(~AsposeCells.LoadDataFilterOptions.DefinedNames));
// Load the workbook
const workbook = new AsposeCells.Workbook(filePath, opts);
// Save the output Excel file, it will break the formula in C1
workbook.save(path.join(dataDir, "outputFilterDefinedNamesWhileLoadingWorkbook.xlsx"));
console.log("FilterDefinedNamesWhileLoadingWorkbook executed successfully.");