简体   繁体   中英

Export the richtext content into excel/csv as it is

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

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 :)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM