Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create multistyled cell with EPPlus library for Excel

Tags:

I use EPPlus for Excel file generation.

I mean I need to convert HTML text (bold, italic, font color, name, size parameters) to Excel Cell. I suppose it needs to create the multi-styled cell, like:

cell text is "hello!"
the style I want is:

he - bold   ll - italic   o! - red colored font   

or (more complex)

hello! - bold   ll - italic (also bold)   o! - red colored (also bold)   

I know about MS OpenXML library (it allows me to do what I need). This is good but bit more complex library for implementation.

like image 512
Anton Norko Avatar asked Apr 02 '12 08:04

Anton Norko


1 Answers

Solved! I can use that:

FileInfo fi = new FileInfo(@"c:\Book1.xlsx");        using (ExcelPackage package = new ExcelPackage(fi))       {         // add a new worksheet to the empty workbook         ExcelWorksheet worksheet = package.Workbook.Worksheets["Inv"];         //Add the headers          worksheet.Cells[2, 1].IsRichText = true;         ExcelRichText ert = worksheet.Cells[2, 1].RichText.Add("bugaga");         ert.Bold = true;         ert.Color = System.Drawing.Color.Red;         ert.Italic = true;          ert = worksheet.Cells[2, 1].RichText.Add("alohaaaaa");         ert.Bold = true;         ert.Color = System.Drawing.Color.Purple;         ert.Italic = true;          ert = worksheet.Cells[2, 1].RichText.Add("mm");         ert.Color = System.Drawing.Color.Peru;         ert.Italic = false;         ert.Bold = false;           package.Save();       } 
like image 87
Anton Norko Avatar answered Sep 22 '22 19:09

Anton Norko