【问题标题】:Get all bold words from excel column with Pandas使用 Pandas 从 excel 列中获取所有粗体字
【发布时间】:2021-03-11 23:12:44
【问题描述】:

使用 Pandas 函数 pd.read_excel 读取文件时,是否可以在 excel 字段中获取粗体字?

我使用函数 df.itertuples() 获取所有行。

我希望在每一行中获取第二列中所有粗体字。 这可能吗?

【问题讨论】:

    标签: python excel pandas


    【解决方案1】:

    你需要额外的包。

    from styleframe import StyleFrame
    
    df = StyleFrame.read_excel('test.xlsx', read_style=True, use_openpyxl_styles=False)
    
    for text in df["Colname"]: # replace Colname
        if text.style.bold:
            print(text)
            
    

    参考StyleFrame

    【讨论】:

    • 这不是很好。它一直为粗体字段返回 False。
    • 我切换到 xlrd。我已经用 load_workbook() 加载了文件并设置了formatting_info=True。当文件像这样加载时,工作表对象有一个属性 rich_text_runlist_map 解决了我的问题。无论如何谢谢:)
    猜你喜欢
    • 2015-11-11
    • 1970-01-01
    • 2019-02-06
    • 2017-02-18
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多