0

I'm importing an XLSX file into a database using ClosedXML via an ASP.NET/VB.NET. My customer needs to keep formatting of single cells, so the solution is to use the cell's RichText property.

I wrote a piece of code that should tranform RichText object in a HTML string, but the color information is not returned from ClosedXML (it always returns #FFFF3333 whatever the text color is.

Here is my snippet:

Shared Function RichTextToHTML(ByVal rt1 As IXLRichText) As String
    'trasforma una string rich text in html
    Dim ret As String = ""
    If rt1.Text <> "" Then
        For Each rts1 As IXLRichString In rt1
            ret &= "<span style='"
            If rts1.Bold Then
                ret &= "font-weight:bold;"
            End If
            If rts1.Strikethrough Then
                ret &= "text-decoration:line-through;"
            End If
            ret &= "color:#" & rts1.FontColor.ToString & ";"
            ret &= "'>" & rts1.Text & "</span>"
        Next
    End If
    Return ret
End Function

the "rts1.FontColor" never returns the correct color. I also tried with other libraries like SpreadsheetLight, but same result: no color from rich text inside spreadsheet cell.

Any idea?

1 Answers1

0

It is working for me (in version 0.68.1 with C#). This code

IXLCell cell = sheet.Cell(1,1);
cell.RichText.ForEach(rts => Console.WriteLine(rts.Text + " / " + rts.FontColor));

gives the output

red / FFFF0000
blue / Color Theme: Accent5, Tint: 1
green / Color Theme: Accent6, Tint: 1

which is consistent with the file I made in Excel.
But notice that colors from themes don't give a hexadecimal color.

Raidri
  • 17,258
  • 9
  • 62
  • 65