This is what I did, and it works good in plain text
using var Doc = SpreadsheetDocument.Open(CXmlDoc.GetExecutingPath () + "Test.xlsx", true);
var nDoc = Doc.Clone(CXmlDoc.GetExecutingPath() + "Test1.xlsx");
var Sst = nDoc.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
for (var i = 0; i < Sst!.RootElement!.ChildElements.Count(); i++)
{
var e = Sst.RootElement.ElementAt(i);
if (!e.InnerText.Contains("test")) continue;
var NewText = e.InnerText.Replace("test", "NewText");
e.ReplaceChild(new DocumentFormat.OpenXml.Spreadsheet.Text(NewText), e.FirstChild);
}
In the excel cell above, if the text within cell is plain text (unformatted), the word test will be replaced correctly. But not working if the text is formatted (bold in this case). See result below:
3