gpt4 book ai didi

c# - 如何使用 EPPlus 库为 Excel 创建多样式单元格

转载 作者:IT王子 更新时间:2023-10-29 04:38:24 24 4
gpt4 key购买 nike

我使用 EPPlus用于生成 Excel 文件。

我的意思是我需要将 HTML 文本(粗体、斜体、字体颜色、名称、大小参数)转换为 Excel 单元格。我想它需要创建多样式单元格,例如:

单元格文本是“你好!”
我想要的风格是:

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

或(更复杂)

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

我了解 MS OpenXML 库(它允许我做我需要的)。这是一个很好但实现起来有点复杂的库。

最佳答案

解决了!我可以使用它:

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();
}

关于c# - 如何使用 EPPlus 库为 Excel 创建多样式单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9973240/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com