This project has moved and is read-only. For the latest updates, please go here.

Change value of a cell with different name

Aug 11, 2011 at 4:25 PM
Edited Aug 11, 2011 at 4:25 PM

In my worksheet i have cells that have different names. Instead of cell C3, i called it test.

When i try to do:  worksheet.Cell("test").Value = "Hello World!"; it doesn't work.

If i use "C3" it works ok. 

Is it possible to affect this kinda of cells without having to put "C3" ?

Working with Excel 2010, XLSX

Aug 11, 2011 at 4:47 PM

You have a named range so you have to do the following:

var namedCell = workbook.NamedRange("Test").Range.FirstCell();

For more information see Named Ranges in the documentation page.

You have given me an idea though. I think I'm going to implement the following:

var cell = workbook.NamedCell(String);
Aug 11, 2011 at 4:59 PM
Edited Aug 11, 2011 at 4:59 PM

That worked perfectly! Thanks for the quick reply.

Glad i gave you a new idea :)

Aug 12, 2011 at 11:24 AM
Edited Aug 12, 2011 at 12:23 PM

I got 2 questions now:

1. I got this named range and when i do

var testing = workbook.NamedRange("testing");

It clears the values inside the Named Range but it also clears the format of the cells.

How do i only clear the cell values?

2. How do i change a value at a specific range in a namedRange ? For example the i position of the named range ?

Figure it out:

IXLCells testingCells = testing.Range.Cells();
testingCells.ElementAt(i).Value = "something";

Aug 12, 2011 at 9:32 PM

1. I'll add a parameter to .Clear() to specify what you want to clear. In the mean time you could do: range.Value = String.Empty;

2. How are you getting the value "i"? I ask because I think a better way to access cells in range is to use: range.Cell(row, column); or plain old: range.Cells().ForEach(cell =>DoSomethingWith(cell));