V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2019-08-31 15:23:33 +08:00 · 1426 次点击
    这是一个创建于 1693 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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
       2019-08-31 15:44:17 +08:00
    卡在这个思路出不去了。。。
    XxxxD
        2
    XxxxD  
       2019-08-31 19:28:35 +08:00
    有个笨方法,找出最大行和列,然后挨个遍历提取颜色,仅供参考
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   940 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 20:07 · PVG 04:07 · LAX 13:07 · JFK 16:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.