The code to add a name alias is as follows:
activeSheet.AddDefinedName('aaaa', '$D$4:$H$8');
This control only supports alphabetical name aliases. Duplicate or other forms of names will cause this function to return false.
The code to delete a name alias is as follows:
activeSheet.DelDefinedName('aaaa');
The code to get name aliases is as follows:
let sheetnames = activeSheet.getDefinedName();
Before deletion:
After deletion:
Log output:
Complete code example:
let wsheet = new websheet('myofdID', yourElement);
/**
* Step 1: Get active sheet
*/
let activeSheet = wsheet.ActiveSheet();
let i = 1;
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
activeSheet.SetCellValue(3, i, i++);
let r = 1;
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(r, 3, r++);
activeSheet.SetCellValue(1, 1, '$D$4:$H$8');
/**
* Step 2: Add an alias named 'aaaa'
*/
activeSheet.AddDefinedName('aaaa', '$D$4:$H$8');
/**
* Print all aliases
*/
let sheetnames = activeSheet.getDefinedName();
for (let rrr = 0; rrr < sheetnames.length; rrr++) {
const onename = sheetnames[rrr];
console.log('Before row deletion: '+onename.name + onename.refersTo);
}
let redFill = new websheet.Model.Fill();
redFill.setColor('#FF0000')
activeSheet.SetCellFill('D4', redFill);
activeSheet.SetCellFill('H8', redFill);
activeSheet.DelRowStart(3, 4); //Delete 4 rows starting from row 3
/**
* Print all aliases again
*/
let sheetnames2 = activeSheet.getDefinedName();
for (let rrr = 0; rrr < sheetnames2.length; rrr++) {
const onename = sheetnames2[rrr];
console.log('After row deletion: '+onename.name + onename.refersTo);
}
/**
* Delete alias
*/
activeSheet.DelDefinedName('aaaa')
/**
* Print after deletion
*/
let sheetnamesd = activeSheet.getDefinedName();
console.log('Name count after deletion: '+sheetnamesd.length);
wsheet.BuildSheet();
wsheet.Draw();