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
leisurelylicht
V2EX  ›  Python

关于 openpyxl 的使用方法

  •  
  •   leisurelylicht · 2017-05-17 15:05:11 +08:00 · 2044 次点击
    这是一个创建于 2529 天前的主题,其中的信息可能已经有所发展或是发生改变。

    请问在 openpyxl 中如何判断一个单元格的类型?

    类似于 xlrd 中的

    sheet.cell_type(row, 8) == xlrd.XL_CELL_DATE

    openpyxl 中关于数据格式的定义如 xlrd.XL_CELL_DATE,xlrd.XL_CELL_NUMBER 之类的是在哪定义的?

    3 条回复    2017-05-17 16:19:45 +08:00
    weyou
        1
    weyou  
       2017-05-17 15:16:29 +08:00
    type(ws.cell(row=1, column=1).value)
    leisurelylicht
        2
    leisurelylicht  
    OP
       2017-05-17 15:35:54 +08:00
    @weyou openpyxl 直接使用了 python 的内置类型吗?
    weyou
        3
    weyou  
       2017-05-17 16:19:45 +08:00
    @leisurelylicht cell 的值在读取 /写入的时候 openpyxl 会负责映射 Excel 数据类型 to/from 相应的 Python 类型
    你也可以用 ws.cell(row=1, column=1).data_type 查看数据类型。不过一般 data_type 很少用到,直接查看 value 的类型就好了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2955 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 03:30 · PVG 11:30 · LAX 20:30 · JFK 23:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.