Retrive/ update cell by name

Hi, I need to read and write data in excel file based on cell name for example: cell D7 is name as :Title" E3 as DOB, G8 as Amount.

I am doing below code
cells c1 = worksheet.cells
foreach(cell c in c1)
{ if(c.Name =“DOB”)
c.PutValue(“02/12/1989”)
}

but aove code is not work
aspose is giving c.name as E3 instead of DOB.

kindly help hoe to retrive data by cell name


Hi,

Thanks for your posting and using Aspose.Cells for .NET.

First you will access the cell by the range name using the Workbook.Worksheets.GetRangeByName() method.

After that you will extract the actual cell name using Range.RefersTo property. Then you will be able to access your actual cell.

Please see the following code for your help.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.Worksheets[0];


//Access your cell by its range name

Range rng = workbook.Worksheets.GetRangeByName(“MyCell”);


//Extract the actual cell name using its Range.RefersTo property

string actualCellName = rng.RefersTo.Split(new string[] { “!” },StringSplitOptions.None)[1].Replace("$", “”);


//Access the actual cell

Cell actualCell = worksheet.Cells[actualCellName];