【问题标题】:find bold text in excel sheet using C#使用 C# 在 Excel 工作表中查找粗体文本
【发布时间】:2010-06-26 13:49:11
【问题描述】:

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

【问题讨论】:

    标签: c# .net excel


    【解决方案1】:

    是的,您将需要 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;
    }
    

    【讨论】:

    • 非常感谢!你帮了我很多。我现在可以检查整个单元格文本以进行粗体范围测试; bool isBold = (bool)test.Font.Bold;
    • 不错的答案,我想您对使用互操作检测包含数据透视表的单元格了解不多?我在这里问了一个问题:stackoverflow.com/questions/35623752/…
    猜你喜欢
    • 1970-01-01
    • 2016-03-18
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-09
    • 2016-03-14
    相关资源
    最近更新 更多