推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
maryxmas
V2EX  ›  Python

有人处理 excel 提取 cell 里多个文本不同颜色的吗?

  •  
  •   maryxmas · Aug 31, 2019 · 2147 views
    This topic created in 2589 days ago, the information mentioned may be changed or developed.
    sheet.rang('A1').font.ColorIndex 能得到 A1 cell 里文本的颜色 index。

    但。。如果 A1 里有多个以空格隔开的文本,每个文本的颜色不同,如何提取这些文本对应的颜色呢?

    于是又发现可以用整个:
    sheet.rang('A1).GetCharacters(5,2).font.ColorIndex

    但。。这个只能用在已知这个字符串的位置从而提取其颜色代码。

    如果不知道字符串的位置,只知道字符串的 pattern,如何实现提取该字符串的颜色呢?

    比如待处理的 cell 里有如下的字符串:
    ‘ 05/12/2018----06/01/2019 (multiple space) 09/02/2019----11/02/2019 ‘
    '05/01/2018----06/01/2018'字体是黑色的,'09/02/2018----11/02/2018 ’字体是蓝色的。

    预期输出为:
    ['05/01/2018','06/01/2018','Black']
    ['09/02/2018','11/02/2018','Blue']
    maryxmas
        1
    maryxmas  
    OP
       Aug 31, 2019
    卡在这个思路出不去了。。。
    XxxxD
        2
    XxxxD  
       Aug 31, 2019
    有个笨方法,找出最大行和列,然后挨个遍历提取颜色,仅供参考
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2327 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:22 · PVG 19:22 · LAX 04:22 · JFK 07:22
    ♥ Do have faith in what you're doing.