Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: How to bold specific text inside a cell and delete some html tags after bolding

$
0
0
Pick up the latest source code and use the following:
        var wb = new XLWorkbook();
        var ws = wb.AddWorksheet("Sheet");
        ws.FirstCell().Value = "<b>test</b>" + System.Environment.NewLine + "test1";
        ws.FirstCell().RichText.Substring(3, 4).SetBold();
        ws.FirstCell().RichText.ForEach(richString => richString.Text = richString.Text.Replace("<b>", "").Replace("</b>", ""));
The problem is that when you change the formatting of a rich text, Excel splits the string into multiple "runs" (each with its own formatting). If you want to modify the text then you have to go through each rich string inside the RichText and modify it independently.

To make it clearer put a breakpoint after the .SetBold() and inspect the RichText. You'll see that it's now a collection of rich strings and it has 3 items. The second one is in bold.

/Manuel

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>