Jatin Kumar
Jatin Kumar

Reputation: 21

C# ClosedXML Rich text implement in range not in cell

I want to insert rich text in a range of my excel sheet, not in particular cell.

for eg: I want to insert ABCDEFGH; IJKLMNOPQ in a range where AB...H will come in red color and IJ....Q will come in blue color. enter image description here

How will i implement it using closedxml ?

Upvotes: 1

Views: 1674

Answers (1)

husky
husky

Reputation: 87

try this please

var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("B2").RichText.AddText("ABCDEFGH; ").SetFontColor(XLColor.Red);
worksheet.Cell("B2").RichText.AddText("IJKLMNOPQ").SetFontColor(XLColor.BabyBlue);
worksheet.Range(worksheet.Cell("B2"), worksheet.Cell("H2")).Merge();
workbook.SaveAs(@"c:\temp\HelloWorld3.xlsx");

Upvotes: 2

Related Questions