Replace method looking for the text in entire cell


Replace method seems to be looking for the text in the entire cell. Cant I replace part of the text within a cell? or am I missing something?



Hi Kiran,

You can try the following approach:

//Find cell text contains “abc” and replace it with "def"
Cells cells = excel.Worksheets[0].Cells;

Cell cell = null;

cell = cells.FindStringContains(“abc”);
if(cell == null)
string text = cell.StringValue;
cell.PutValue(text.Replace(“abc”, “def”));


Thanks Laurence. This worked great. I have 1 more issue though. I need to look for strings within a cell which starts with “a” & ends with “z” (there can be multiple strings within a cell.) Is there a way I could accomplish this?

If Aspose.Excel supported regular expression it would have been great.



We will investigate the regular expression support.

And I think now it's also easy to meet your need. The following is the sample code:

for(int i = 0; i < cells.Count; i ++)
Cell cell = cellsIdea;
if(cell.Type == CellValueType.String)
string text = cell.StringValue;
//The you can use your regular expression to check the text