EPPlus also supports the ability to insert text in a cell using the Insert() method. For example:
var file = new FileInfo(filePath);
using (var p = new ExcelPackage(file))
{
var wb = p.Workbook;
var ws = wb.Worksheets.FirstOrDefault() ?? wb.Worksheets.Add("Sheet1");
var cell = ws.Cells[1, 1];
cell.IsRichText = true;
cell.RichText.Clear(); // Remove any RichText that may be in the cell already
var s1 = cell.RichText.Add("Section 1.");
var s2 = cell.RichText.Add("Section 2.");
var s3 = cell.RichText.Insert(1, "Section 3.");
s3.Bold = true;
p.Save();
}
Note that the Insert() method does NOT insert at a character index, but at a Section index. Because the sections are zero-indexed, the above code will produce the following text in the cell:
Section 1.Section 3.Section 2.