exceljs

How to Define name for a range using exceljs?


I am using exceljs library to create excel file in javascript now i want to define a name to a range.
It's working for a single cell range but not in the case of multiple cells.
In the case of single cell it work like this:

worksheet.getCell('A1').name = 'PI'

now I want to define name for multiple cells/range but i'ts not working

worksheet.getCell('A1:A6').name = 'PI'

so how to assign a name for a range?


Solution

  • I found the solution here it is:-

    wb.definedNames.add(address,rangename)
    

    Where wb is the excel workbook in which we are working and 'address' is the range address while 'rangename' is the name of the range which you want to give.

    The address must start with the worksheet name. Example sheet1!A1:A2