在EPPLUS RichText中插入文本
我正在使用EPPLUS来写入excel文件,并且我正在使用一些单元格的多样式,问题是我想在这些单元格的特定位置插入文本。
worksheet.Cells[rowNum, columnNum].RichText.Text.Insert(index, string);
原来,上面的代码行会尝试在indexth元素中插入string而不是indexth字符。
我也试过这个:
worksheet.Cells[rowNum, columnNum].RichText..Text.Insert(index,string);
没有string也使用这个插入。
我正在考虑计算每个RichText元素的长度,并向RichText添加一个新元素,其中以前元素的长度= index,但是我正在寻找更好的解决scheme。
由于插入返回一个新的string,其中指定的string插入指定的索引位置在这种情况下,所以你必须做的:
worksheet.Cells[rowNum, columnNum].RichText.Text = worksheet.Cells[rowNum, columnNum].RichText.Text.Insert(index,yourstring);