我如何获得部分细胞的造型在Excel中使用EPpplus? [英] How do I get partial cell styling in excel using EPpplus?
本文介绍了我如何获得部分细胞的造型在Excel中使用EPpplus?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有了斜体一些文字和斜体一些文字不是一个单元格。我如何保存的格式?我看着OfficeOpenXml.Style.ExcelStyle和看到的选项挂粗体,斜体等,但这些应用到整个小区。有没有办法知道哪些文本格式使用eppplus并保存,格式化某种方式?
FileInfo的信息=新的FileInfo (@C:\excel.xlsx);使用
(ExcelPackage包=新ExcelPackage(信息)){
ExcelWorksheet表= package.Workbook.Worksheets [页];
对象文本= sheet.Cells [1,1]。价值;
//如果我这样做的toString,我失去了所有格式:
串textWithOutFormat = text.ToString();
//我假设我会得到它的一些怎么样的呢?
如果(sheet.Cells [1,1] .IsRichText){
//获取RTF或得到哪些项目wrapp富文本
//不知道如何得到它。
}
}
解决方案
要写几个风格的单元格:
FileInfo的网络连接=新的FileInfo(@C:\File.xlsx);使用(ExcelPackage包=新ExcelPackage(FI))
{
ExcelWorksheet工作表= package.Workbook.Worksheets [表]
;
worksheet.Cells [1,1] .IsRichText =真;
ExcelRichText富文本= worksheet.Cells [1,1] .RichText.Add(测试斜体);
的富文本.Italic = TRUE;
富文本= worksheet.Cells [1,1] .RichText.Add(试验2);
的富文本.Italic = FALSE;
package.Save();
}
要读几个风格的单元格:
的foreach(在cell.RichText VAR部分)
{
如果(part.Bold)
//办?员工
如果(part.Italic)
//办?员工
}
I have a cell that has some text in italics and some text not in italics. How do I preserve the formatting? I looked at the OfficeOpenXml.Style.ExcelStyle and see the options hanging off for bold, italic, etc but those apply to the whole cell. Is there a way to tell which text is formatted a certain way using eppplus and to preserve that formatting?
FileInfo info = new FileInfo(@"C:\excel.xlsx");
using (ExcelPackage package = new ExcelPackage(info)) {
ExcelWorksheet sheet = package.Workbook.Worksheets["Sheet"];
object text = sheet.Cells[1, 1].Value;
// if I do toString, I lose all formatting:
string textWithOutFormat = text.ToString();
// I would assume I'd get it some how like this?
if (sheet.Cells[1, 1].IsRichText) {
// get rich text formatting or get what items are wrapp in rich text
// no idea how to get it.
}
}
解决方案
To write a cell with several style :
FileInfo fi = new FileInfo(@"c:\File.xlsx");
using (ExcelPackage package = new ExcelPackage(fi))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets["Sheets"];
worksheet.Cells[1, 1].IsRichText = true;
ExcelRichText richtext = worksheet.Cells[1, 1].RichText.Add("Test Italic");
richtext .Italic = true;
richtext = worksheet.Cells[1, 1].RichText.Add("Test 2");
richtext .Italic = false;
package.Save();
}
To read a cell with several style :
foreach(var part in cell.RichText)
{
if (part.Bold)
// Do staff
if (part.Italic)
// Do staff
}
这篇关于我如何获得部分细胞的造型在Excel中使用EPpplus?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文