Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
If there are too many defined names or named ranges in the Excel files, we have to clear some for they are not referred again.
To remove a named range from Excel, you can follow these steps:
With Aspose.Cells for Node.js via C++, you can remove named ranges or defined names by text or index in the list.
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Book1.xlsx");
// Instantiate a new Workbook.
const workbook = new AsposeCells.Workbook(filePath);
// Get all the worksheets in the book.
const worksheets = workbook.getWorksheets();
// Deleted a named range by text.
worksheets.getNames().remove("NamedRange");
// Deleted a defined name by index. Ensure to check the count before removal.
if (worksheets.getNames().getCount() > 0) {
worksheets.getNames().removeAt(0);
}
// Save the workbook to retain the changes.
workbook.save("Book2.xlsx");
Note: if the defined name is referred by formulas, it could not be removed. We only can remove the formula of the defined name.
When we remove a defined name, we have to check whether it is referred by all formulas in the file. In order to improve performance of removing named ranges, we can remove some together.
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, "Book1.xlsx");
// Instantiate a new Workbook.
const workbook = new AsposeCells.Workbook(filePath);
// Get all the worksheets in the book.
const worksheets = workbook.getWorksheets();
// Deleted some defined names.
worksheets.getNames().remove(["NamedRange1", "NamedRange2"]);
// Save the workbook to retain the changes.
workbook.save("Book2.xlsx");
Some Excel files corrupt because some defined names are duplicate. So we can remove these duplicate names to repair the file.
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, "Book1.xlsx");
// Instantiate a new Workbook.
const workbook = new AsposeCells.Workbook(filePath);
// Get all the worksheets in the book.
const worksheets = workbook.getWorksheets();
// Deleted some defined names.
worksheets.getNames().removeDuplicateNames();
// Save the workbook to retain the changes.
workbook.save("Book2.xlsx");
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.