[英]How to remove part of string and save style format
您需要使用单元格的RichText
属性。 首先从单元格复制缩短的文本,然后清除单元格并插入RichText
的其余部分:
int firstDot = ws.Cell(1, 1).GetString().IndexOf(".");
IXLFormattedText<IXLRichText> strWithoutBold = ws.Cell(1, 1).RichText.Substring(firstDot);
ws.Cell(1, 1).RichText.ClearText();
foreach (IXLRichString rt in strWithoutBold)
{
ws.Cell(1, 1).RichText.AddText(rt.Text).CopyFont(rt);
}
PS1:当您使用点的索引时,您保留点(粗体)。 您可能需要+1
索引。
PS2:与您之前的问题类似,这仅适用于最高 0.92 的 ClosedXML 版本。 也许我会看看图书馆,并尝试制定一个更简单的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.