Search code examples
excelepplus

EPPLUS - Rename Cell


I'm using EPPLUS to build custom Excel spread sheets. One functionality that I'm missing is to change the name of a cell. Is this somehow possible with EPPLUS? If not are there any other ways of doing it?


Solution

  • Suppose that book is your workbook and sheet is your worksheet. Let try this code snippet

    var cell = sheet.Cells["C2"]; // Cell or Range you want to name
    sheet.Names.Add("The_Name_Here", cell);
    

    The name will be added to sheet. If you want to access the name in the whole workbook, try:

    var cell = sheet.Cells["C2"]; // Cell or Range you want to name
    book.Names.Add("The_Name_Here", cell);
    

    Depend on your need the scope of the name can be sheet.Names or book.Names. I don't know how to modify an existing name but sure that 1 cell/range may have multiple names.