使用C#在Excel工作表中查找粗体文本

des*_*man 2 .net c# excel

如何在Excel工作表的单元格中查找粗体文本?我正在使用C#,OLEDB和ADO.NET来读取xls文件,但我没有解决如何解决我的任务.我需要使用Iterop.Excel吗?

vol*_*ody 7

是的,您需要Interop.Excel

using Microsoft.Office.Interop.Excel;

int FindFirstBold(Range cell)
{    
    for (int index = 1; index <= cell.Text.ToString().Length; index++)
    {
        Characters ch = cell.get_Characters(index, 1);
        bool bold = (bool) ch.Font.Bold;
        if(bold) return index;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)