When reading the Rich Text present in Excel column using open XML its taking it as plain text RRS feed

  • Question

  • Hello All,

    When i am reading excel columns using open Xml in C# everything is working fine except the column that contain Rich Text (ex: bold, italic,color,size). Its reading the Rich Text content as plain text. As we know for Rich Text in open XML we get the text as Runs (C# object) which contains the text as value and rpr as run properties. I have also written the code to convert Runs to html. But the issue is that for some Rich Text format its reading it as Runs but most of the Rich Text its reading it as plain text.

    The issue i am getting is, for some rich text its creating RUN and for some of the rich text its not creatingRUN.

    Let me give the example for more understanding:

    Suppose i have two cells in excel which contains the below text.

    1. Rich Text 1

    2. RichText 2

    Now when i read these cells using the below code

    var stringTable =spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();

    if (stringTable.SharedStringTable.ElementAt(index1).ChildElements.GetItem(0).GetType().Name == "Run")

    Custom code to convert Rich text to HTML...




    Read the plain text...


    Though both the cell contains rich text, one is going in RUN block and one is going in Plain text bloc.

    Also, one thing that i have noticed is when i use standard color for text its consider it as RUNS and when i use color apart from the standard color it does not consider it as RUNS. Same behavior occurs for different combination of text viz. bold, italic, underline etc

    Friday, April 24, 2015 6:05 AM