Insert Value in Cell using Custom "Cell-Name"

i have following problem:

1. i open an excel-template
2. i define a custom cell-name ("A1" --> "Name")
3. i save this file
4. my code opens this excel-file and try to insert a value with:

Cell locMyNameCell = locWorksheet.Cells["Name"];
locMyNameCell.PutVaule("Dave");

no cell can instantiate with this code (invalid cell name). When i use:
Cell locMyNameCell = locWorksheet.Cells["A1"];
locMyNameCell.PutVaule("Dave");

this works fine but is no approach for my project. i dont no the cell ("A1") on design time. i must use custom cell name.

how can i insert a value using custom cell names?

regards,

dave

Please try:

Range range = workbook.GetRangeByName("Name");

range[0, 0].PutValue("Dave");

I had the same question.

I tried your suggestion, but get the error:

GetRangeByName is not a member of 'Aspose.Cells.Workbook'

Hi Guys,

Sorry by mistake, Actually the GetRangeByName() is a method of Worksheets class and not Workbook class. Please refer the following code:

Workbook workbook = new Workbook();

Worksheet worksheet1 = workbook.Worksheets[0];

Range range1 = worksheet1.Cells.CreateRange("A1", "A1");

range1.Name = "MyRange";

Range range2 = workbook.Worksheets.GetRangeByName("MyRange");

range2[0,0].PutValue("Hello World!");

workbook.Save("d:\\namedrange.xls");

Regards

Amjad Sahi

Aspose Nanjing Team