Free Support Forum - aspose.com

Create a named range in Excel worksheet in .NET

Hi

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”;

etcTempWorkbook.Worksheets.RemoveAt(0);

etcTempWorksheet.Cells[0,0].PutValue(1);

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

Hi,
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];

worksheet.Cells[0,0].PutValue(1);

<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:

http://www.aspose.com/docs/display/cellsnet/Named+Ranges

Thank you.