diff --git a/ClosedXML/Excel/Cells/XLCell.cs b/ClosedXML/Excel/Cells/XLCell.cs index 2a163a9..8308ed7 100644 --- a/ClosedXML/Excel/Cells/XLCell.cs +++ b/ClosedXML/Excel/Cells/XLCell.cs @@ -1586,6 +1586,9 @@ private bool SetEnumerable(object collectionObject) { + // IXLRichText implements IEnumerable, but we don't want to handle this here. + if ((collectionObject as IXLRichText) != null) return false; + var asEnumerable = collectionObject as IEnumerable; return InsertData(asEnumerable) != null; } diff --git a/ClosedXML_Examples/Styles/UsingRichText.cs b/ClosedXML_Examples/Styles/UsingRichText.cs index af0ad36..3ceed77 100644 --- a/ClosedXML_Examples/Styles/UsingRichText.cs +++ b/ClosedXML_Examples/Styles/UsingRichText.cs @@ -91,7 +91,21 @@ if(richText.Bold) ws.Cell(3, 2).Value = String.Format("\"{0}\" is Bold.", richText.Text); } - + + + // Now we'll build a cell with rich text, and some other styles + cell = ws.Cell(5, 1); + + // Add the text parts + cell.RichText.AddText("Some").SetFontColor(XLColor.Green); + cell.RichText.AddText(" rich text ").SetFontColor(XLColor.Blue).SetBold(); + cell.RichText.AddText("with a gray background").SetItalic(); + + cell.Style.Fill.SetBackgroundColor(XLColor.Gray); + + ws.Cell(5, 2).Value = cell.RichText; // Should copy only rich text, but not background + + ws.Columns().AdjustToContents(); wb.SaveAs(filePath); diff --git a/ClosedXML_Tests/Resource/Examples/Styles/UsingRichText.xlsx b/ClosedXML_Tests/Resource/Examples/Styles/UsingRichText.xlsx index 8fd19ce..c44ada1 100644 --- a/ClosedXML_Tests/Resource/Examples/Styles/UsingRichText.xlsx +++ b/ClosedXML_Tests/Resource/Examples/Styles/UsingRichText.xlsx Binary files differ