Export the richtext content into excel/csv as it is

1.2k Views Asked by At

I have a form with multiple fields like textbox, email, radio and richtext editor. Multiple submissions are going to happen on the form. I want to export the submitted records list to an Excel or csv file keeping the richtext content as html content. for example, In richtext i entered "Hello I am bunny" in bold that means it's internal content is "<strong>Hello I am bunny</strong>". so While exporting to excel I want the richtext content as "Hello I am bunny". Is there any idea ?

Thanks in advance

1

There are 1 best solutions below

0
On

You could parse the string using regex. I posted an example to explain what I mean.

    Regex startTag = new Regex(@"<\w+>");

    List<string> tagWords = new List<string>();
    tagWords.Add("<strong>Hello I am bunny</strong>");
    tagWords.Add("<i>Hello this text is italic</i>");
    tagWords.Add("<small>Hello this text is small</small>");

    foreach (string item in tagWords)
    {
       Match start = startTag.Match(item);
       Console.WriteLine(item.Substring(start.Length,item.Length-start.Length*2)-1));
    }

Once you have the parsed string you should be able to just export it to the excel file.

Output is posted below, let me know if you need anymore help :)

enter image description here