我是靠谱客的博主 痴情溪流,最近开发中收集的这篇文章主要介绍python判断excel单元格为空,使用xlrd库读取Excel文件时如何检测单元格是否为空?...,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

I handle Excel files using the functions row_values and col_values:

import xlrd

workbook = xlrd.open_workbook( filename )

sheet_names = workbook.sheet_names()

for sheet_name in sheet_names:

sheet = workbook.sheet_by_name( sheet_name )

# ...

row_values = sheet.row_values( rownum )

# ...

col_values = sheet.col_values( colnum )

For example, I get col_values as list. What if I meet an empty cell in some column? For example a cell (1,1) is not empty, a cell (1,2) is empty and a cell (1,3) is not empty? How can I detect that the cell (1,2) is empty?

Is this true that I get a list with an empty string as a value of an empty cell (for most well-known programs which generate Excel files)?

解决方案

You could be explicit and check that sheet.cell_type(rowno, colno) in (xlrd.XL_CELL_EMPTY, xlrd.XL_CELL_BLANK) but the docs state the value will be u'' where those are the case anyway.

Instead of using row_values, you could also use row(n) which returns a list of Cell objects which have .value and .cell_type attributes.

最后

以上就是痴情溪流为你收集整理的python判断excel单元格为空,使用xlrd库读取Excel文件时如何检测单元格是否为空?...的全部内容,希望文章能够帮你解决python判断excel单元格为空,使用xlrd库读取Excel文件时如何检测单元格是否为空?...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(36)

评论列表共有 0 条评论

立即
投稿
返回
顶部