1

I am using a Rich text component from which I take input and store the generated HTML string in Database. While generating Excel, I along with this HTML string perform a few other operations (this does not change the HTML string). However, when I view the HTML string in Excel, it simply removes all the formatting and displays just the plain text.

I tried the following code:

Microsoft.Office.Interop.Excel.Range range = oSheet.get_Range(CellFrom, CellTo);                
htmlString = htmlString.Replace("<br/>", "\r\n").Replace("</br>", "\r\n").Replace("<br>", "\r\n").Replace("</p>", "\r\n").Replace("<p>", "");
range.FormulaR1C1 = Regex.Replace(htmlString, "<.*?>", String.Empty);
range.Rows.AutoFit();

I also tried copying the HTML string to the clipboard and then paste it to Excel but that started showing popups to allow.

Is there a workaround for this ?

Yash Saraiya
  • 1,035
  • 1
  • 20
  • 40
  • Paste is the only way. You cant have a HTML as a cell text and expect to see the format. Its just text. For pop ups, depends on what have you got in your HTML. I guess JS? – cyboashu Dec 20 '16 at 08:03
  • Just curious, what are you trying to do? – cyboashu Dec 20 '16 at 08:07
  • All I am trying to do is accept a few notes written inside the RichText editor through UI and simply display those notes as is in the Excel. With regards to pop-up, they seems to be some security related alerts. – Yash Saraiya Dec 20 '16 at 08:30
  • Yeah I've answered this, 2 seconds - let me know if this is different – Jeremy Thompson Dec 20 '16 at 08:32
  • With HTML, its quite difficult, but if its just user supplied text, when trying to paste, you shouldn't get any pop-ups. One approach could be to save the html in temp location, add a webbrowser control on the sheet and load html to display. – cyboashu Dec 20 '16 at 08:33

0 Answers0