Question posted 2012 · +12 upvotes
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 multistyled cell, like:
cell text is “hello!” 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 do what I need). This is good but bit more complex library for implementation.
Thanks.
Accepted answer +13 upvotes
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();
}
Excel VBA objects referenced (3)
System.Drawing— Working with shapes (drawing objects)Workbook— Workbooks and WorksheetsWorkbook— Add a Table of Contents to a Workbook
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- How should I escape commas and speech marks in CSV files so they work in Excel? +136 (2012)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
excel solutions on this site
.