Search code examples
c#epplus

EPPlus - ExcelNamedRange - Is there a function like RefersTo


In the original Excel Objects I have the property RefersTo like:

workbook.Names("TestRange").RefersTo

Is there an equivalent in EPPlus?

UPDATE

Here is a screenshot of the Excel Dialog and the field I want to write to. To open this Dialog in Excel goto: Formulars - Names-Manager

here is a screenshot of the Excel Dialog and the field I want to write to


Solution

  • Is that you are searching for?

    sheet.Names["RangeName"].Start.Column
    sheet.Names["RangeName"].End.Column
    sheet.Names["RangeName"].Start.Row
    sheet.Names["RangeName"].End.Row
    

    EDIT

    RefetsTo is the range/address of a named range.

    To add a named range :

    ExcelRange range = ws.Cells["A1:E5"];  // this is the RefersTo
    ws.Names.Add("test", range);
    

    To edit a named range :

    ExcelRange newrange = ws.Cells["A1:F6"];  // this is the RefersTo
    ws.Names["test"].Address = newrange.Address;
    

    EDIT

    To add a named range, that use a formula :

    ws.Names.AddFormula("test2", "MAX(8,10,6,4,2)");