Free Support Forum -

Create a named range in Excel worksheet in .NET


I want to set a name to a cell like something i can do in excel with Name box
i use blow code but it show that name hasn’t setter.

var etcTempWorkbook = new Workbook();

int etcTempWorksheetIndex = etcTempWorkbook.Worksheets.Add();

var etcTempWorksheet = etcTempWorkbook.Worksheets[etcTempWorksheetIndex];

etcTempWorksheet.Name = “Result Worksheet”;



etcTempWorksheet.Cells[0, 0].Name = “Number1”;

Please use Cells.CreateRange() method to create a range based on your desired cell/cells.

See the sample code for your reference:

//Instantiating a Workbook objectWorkbook workbook = new Workbook();

//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];


<b>//Creating a named range
Range range = worksheet.Cells.CreateRange(“A1”, “A1”);
//Or simply use</b>

**//Range range = worksheet.Cells.CreateRange(“A1”);**

**//Setting the name of the named range**

**range.Name = “Number1”;**

//Or set the value to range cell

//range.Value = 1;

See the topic for your reference:

Thank you.