如何使用 C# 检查 excel 文件中 wrapText 的粗体样式
How to check bold style in wrapText in excel file using c#
如何检查 Excel sheet 单元格内的粗体文本?我正在使用 C#、Epplus 读取 excel 文件,但我没有解决如何解决我的 task.So 你能告诉我我是如何解决它的吗?
输入:在 excel
的单元格中
• On Command
• **On proceeds**
• Exclude guidance
• **On Demand**
输出:
• **On proceeds**
• **On Demand**
不确定您真正想要的是什么,但假设您有这样的电子表格:
如果粗体文本为红色,这会提取所有带有粗体文本的单元格:
using (var package = new ExcelPackage(new FileInfo(path)))
{
var sheet = package.Workbook.Worksheets[1];
for (int i = 1; i <= 4; ++i)
{
var cell = sheet.Cells[1, i];
if (cell.IsRichText) {
foreach (var element in cell.RichText)
{
if (element.Bold)
Console.WriteLine("Rich Text cell {0}: bold text: [{1}]", i, element.Text.Trim());
}
}
else {
if (cell.Style.Font.Bold)
Console.WriteLine("Single-line cell {0}: bold text: [{1}]", i, cell.Value);
}
}
}
输出:
Single-line cell 1: bold text: [Bold]
Rich Text cell 3: bold text: [Bold]
Rich Text cell 4: bold text: [Bold00]
Rich Text cell 4: bold text: [Bold01]
如何检查 Excel sheet 单元格内的粗体文本?我正在使用 C#、Epplus 读取 excel 文件,但我没有解决如何解决我的 task.So 你能告诉我我是如何解决它的吗?
输入:在 excel
的单元格中 • On Command
• **On proceeds**
• Exclude guidance
• **On Demand**
输出:
• **On proceeds**
• **On Demand**
不确定您真正想要的是什么,但假设您有这样的电子表格:
如果粗体文本为红色,这会提取所有带有粗体文本的单元格:
using (var package = new ExcelPackage(new FileInfo(path)))
{
var sheet = package.Workbook.Worksheets[1];
for (int i = 1; i <= 4; ++i)
{
var cell = sheet.Cells[1, i];
if (cell.IsRichText) {
foreach (var element in cell.RichText)
{
if (element.Bold)
Console.WriteLine("Rich Text cell {0}: bold text: [{1}]", i, element.Text.Trim());
}
}
else {
if (cell.Style.Font.Bold)
Console.WriteLine("Single-line cell {0}: bold text: [{1}]", i, cell.Value);
}
}
}
输出:
Single-line cell 1: bold text: [Bold]
Rich Text cell 3: bold text: [Bold]
Rich Text cell 4: bold text: [Bold00]
Rich Text cell 4: bold text: [Bold01]