This project has moved. For the latest updates, please go here.

What IsRichText Property does?

Mar 30, 2010 at 2:54 PM

What  IsRichText property does?

Coordinator
Mar 30, 2010 at 3:47 PM

:-) ok you really want to do this...

I really don't recommend this at all but, you can try...

            ws.Cells["A1"].IsRichText = true;
            ws.Cells["A1"].Value = "<r><rPr><sz val=\"11\" /><color rgb=\"FFFF0000\" /><rFont val=\"Calibri\" /><family val=\"2\" /><scheme val=\"minor\" /></rPr><t>te</t></r><r><rPr><b /><sz val=\"11\" /> <color theme=\"1\" /><rFont val=\"Calibri\" /><family val=\"2\" /> <scheme val=\"minor\" /> </rPr><t>st</t> </r>";

You have to be really carefull here. This is the raw format. If you get it wrong the sheet will be corruppted. 
I will proberbly do something to support rich text in the future, so this behavior will change.
I cant give you any more that that, the rest you have to figure out yourself
Jan
Sep 29, 2010 at 10:39 PM

Thanks for the info, Jan. I was looking for this functionality specifically. I need format text in a single cell where some of the text is italic, while other text is bold. I look forward to any updates for rich text support.

Coordinator
Sep 30, 2010 at 7:16 AM

From 2.7.0.1, use the RichText property instead, like in Sample 6...

            //Use the RichText property to change the font for the directory part of the cell
            var rtDir = ws.Cells["A1"].RichText.Add(dir);
            rtDir.FontName = "Consolas";
            rtDir.Size=18;

Jan

Apr 2, 2011 at 8:52 AM

I know this is old, but it looks similar to what I'm after.

I want to have 2 or 3 different colours of text in the same cell.

I'm using it in a for loop that checks the value of a variable and puts it into a cell.

So the value might be 'Red' so It add's that to cell A12 with a red colour. The next loop might be blue, so it will add 'Blue' to the cell A12 in a blue colour.

The Cell A12 would now say "Red Blue" with red being red and blue being blue.

Would using the RichText property allow me to do this
? and if it will, can you please provide me with an example?

 

Coordinator
Apr 3, 2011 at 7:20 PM

Have a look at sample 6.

This is for a comment but it works very similar for cells...

 //Format the code using the RichText Collection
            var rc = comment.RichText.Add("//Format the Size and Count column\r\n");
            rc.FontName = "Courier New";
            rc.Color = Color.FromArgb(0, 128, 0);
            rc = comment.RichText.Add("ws.Cells[");
            rc.Color = Color.Black;
            rc = comment.RichText.Add("\"B3:B42\"");
            rc.Color = Color.FromArgb(123, 21, 21);
            rc = comment.RichText.Add("].Style.Numberformat.Format = ");
            rc.Color = Color.Black;
            rc = comment.RichText.Add("\"#,##0\"");
            rc.Color = Color.FromArgb(123, 21, 21);
            rc = comment.RichText.Add(";");
            rc.Color = Color.Black;

Apr 7, 2011 at 6:52 AM

Thank you for that Jankallman. I will try it as soon as I can and let you know how I go :)

Sep 14, 2011 at 10:26 AM
jankallman wrote:

:-) ok you really want to do this...

I really don't recommend this at all but, you can try...

            ws.Cells["A1"].IsRichText = true;
            ws.Cells["A1"].Value = "<r><rPr><sz val=\"11\" /><color rgb=\"FFFF0000\" /><rFont val=\"Calibri\" /><family val=\"2\" /><scheme val=\"minor\" /></rPr><t>te</t></r><r><rPr><b /><sz val=\"11\" /> <color theme=\"1\" /><rFont val=\"Calibri\" /><family val=\"2\" /> <scheme val=\"minor\" /> </rPr><t>st</t> </r>";

You have to be really carefull here. This is the raw format. If you get it wrong the sheet will be corruppted. 
I will proberbly do something to support rich text in the future, so this behavior will change.
I cant give you any more that that, the rest you have to figure out yourself
Jan

Hello, I would like to make this work but i cant. The resulting file displays the tags. Can anybody point me to the right direction? Below is my code:

Protected Sub btnImport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnImport.Click

Dim location = Server.MapPath("Temp")

Dim file As System.IO.FileInfo = New System.IO.FileInfo(location + "\Import.xlsm")
        Using xlPackage As OfficeOpenXml.ExcelPackage = New OfficeOpenXml.ExcelPackage(file)

Dim wSheet As OfficeOpenXml.ExcelWorksheet = xlPackage.Workbook.Worksheets("Scorecard")

wSheet.Cells(11, 11).IsRichText = True           

wSheet.Cells(11, 11).Value = Nothing           

wSheet.Cells(11, 11).Value = "<r><rPr><sz val=""11"" /><color rgb=""FFFF0000"" /><rFont val=""Calibri"" /><family val=""2"" /><scheme val=""minor"" /></rPr><t>te</t></r><r><rPr><b /><sz val=""11"" /> <color theme=""1"" /><rFont val=""Calibri"" /><family val=""2"" /> <scheme val=""minor"" /> </rPr><t>st</t> </r>"

xlPackage.Save()       

End Using

End Sub

Sep 14, 2011 at 10:28 AM

what i'm trying to achieve is to print to excel an html source, but since html tags aren't supported by EPPlus, the nearest thing i could do is to parse the html into RTF format. Can anybody give me an idea as to how I can achieve this? thanks!