1

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

I want to convert excel cell value in to html. Ie: 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?

Anth12
  • 1,869
  • 2
  • 20
  • 39
Gayathri
  • 85
  • 2
  • 11
  • [This link](http://answers.microsoft.com/en-us/office/forum/office_2007-excel/find-and-replace/7847950a-08fd-48e8-8618-6decf475b6de?page=3&msgid=dbbcb5b3-c543-4931-aa3a-59f076e09673) may be of interest. –  Dec 02 '14 at 08:45
  • Possible duplicate of [Convert Rich Text to HTML formatting tags](https://stackoverflow.com/questions/33620147/convert-rich-text-to-html-formatting-tags) – sjy Aug 01 '18 at 01:58

3 Answers3

3

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(bold){
                 if (html.Length == 0)
                      html.Append("<b>");
                 html.Append(ch.Text);
         }
    }
    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)

Community
  • 1
  • 1
Tyress
  • 3,573
  • 2
  • 22
  • 45
0
  1. On the workbook, go to the File tab and click Save As.

If you want to export some portion of data only, e.g. a range of cells, pivot table or graph, select it first.

  1. In the Save As dialog, choose one of the following:

Web Page (.htm; .html). This will save your workbook or the selection to a web page and create a supporting folder that will store all of the page's supporting files such as images, bullets and background textures. Single File Web Page (.mht; .mhl). This will save your workbook or the selection to a single file with supporting files embedded into the web page

i think this is what u r looking!

MMM
  • 3,132
  • 3
  • 20
  • 32
0

One of the way is

Spreadsheet document = new Spreadsheet("SimpleReport.xls");
// Get Worksheet
Worksheet worksheet = document.Workbook.Worksheets[0];
// Export to HTML
worksheet.SaveAsHTML("SimpleReport.htm");
// Close Spreadsheet 
//enter code here
document.Close();

then you can read html and replace tags to get output

Akshay Randive
  • 384
  • 2
  • 10
  • @Gayathri this may help you more [click here](http://stackoverflow.com/questions/6850850/reading-file-content-to-string-in-net-compact-framework) – Akshay Randive Dec 02 '14 at 10:10