问题描述
我使用进行Excel文件生成。
单元格文本是hello!
style我想要的是:
他 - bold
ll - italic
o! - 红色字体
或(更复杂)
你好! - bold
ll - 斜体(也是粗体)
o! - 红色(也是粗体)
我知道MS OpenXML库(它允许我做我需要的)。
谢谢。
解决!
我可以使用它:
FileInfo fi = new FileInfo(@c:\Book1.xlsx) ;
使用(ExcelPackage package = new ExcelPackage(fi))
{
//向工作簿中添加新工作表
ExcelWorksheet工作表= package.Workbook.Worksheets [ INV];
//添加标题
workheet.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();
}
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 - boldll - italico! - red colored font
or (more complex)
hello! - boldll - 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.
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的EPPlus库创建多基元单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!