I just wonder whether we can find and replace using Office Excel JS? I have read through their doc but it does not mention about this functionality.
CodePudding user response:
The Range
object has a find
method to search for a specified string within the range. It returns the range of the first cell with matching text.
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
let table = sheet.tables.getItem("ExpensesTable");
let searchRange = table.getRange();
let foundRange = searchRange.find("Food", {
completeMatch: true, // Match the whole cell value.
matchCase: false, // Don't match case.
searchDirection: Excel.SearchDirection.forward // Start search at the beginning of the range.
});
foundRange.load("address");
await context.sync();
console.log(foundRange.address);
});
See Find a string within a range using the Excel JavaScript API for more information.
CodePudding user response:
This function replaceAll would do it