当前位置:   article > 正文

python 判断excel单元格为空_用python检测空白Excel单元格

python判断空白单元格写入

我已经编写了一个python代码,用于将数据从多个excel文件转换为单个csv文件,但是它不起作用。在下面的程序中,我尝试用XL_CELL_EMPTY或XL_CELL_BLANK代替None。但什么都没用。它给出以下错误Traceback (most recent call last):

File "Excel_to_CSV_1.py", line 35, in

while Sh_B1.cell(i,j).value != None :

File "/usr/lib/pymodules/python2.7/xlrd/sheet.py", line 245, in cell

self._cell_types[rowx][colx],

IndexError: array index out of range

这是程序:import xlrd

import os.path

from xlrd import open_workbook,empty_cell

book1 = xlrd.open_workbook("Excel_1.xls")

Sh_B1 = book1.sheet_by_index(0)

book2 = xlrd.open_workbook("Excel_2.xls")

Sh_B2 = book2.sheet_by_index(0)

i = 1

j = 1

file = open("Output.txt", "w")

while Sh_B1.cell(i,j).value != None :

while Sh_B1.cell(i,j).value != None :

D1 = Sh_B1.cell(i,j).value

D2 = Sh_B2.cell(i,j).value

DB1 = str(D1)+ "," + str(D2)

file.write("".join(DB1+ "\n"))

j = j + 1

j = 1

print "j=1"

i = i + 1

file.close

我哪里做错了?

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/698154
推荐阅读
相关标签
  

闽ICP备14008679号