Gayathri Gayathri - 4 months ago 31
HTML Question

Any way to convert excel cell value in to html format?

Any way to convert excel cell value in to html format?

I want to convert excel cell value in to html.
Excell cell Value: 'Am a programmer'
Wanna convert like:

Am a <b>programmer</b>

Am reading excel using excel interop. I can check whether the entire value in excel cell is bold/italic then add html tags accordingly but am unable to check whether any text is bold\italic in between a cell value.

Any way?


You can use this method to get whether each character is bold or not.

A good strategy I think is to use a StringBuilder to build your HTML:

    StringBuilder html = new StringBuilder();
    for (int index = 1; index <= cell.Text.ToString().Length; index++)
        //cell here is a Range object
        Characters ch = cell.get_Characters(index, 1);
        bool bold = (bool) ch.Font.Bold;
                 if (html.Length == 0)
    if (html.Length !=0) html.Append("</b>")

That strategy is only for your text with only one bold word. (Just figure out an algorithm that will close open tags and make a new StringBuilder when a non-bold character is read or when the entire cell has been read)