python的excel⾥单元格为空⽩_Pythonopenpyxl读取Excel⽂
件并为。。。
from openpyxl import load_workbook
import json
wb = load_workbook(filename='Deployment Plan_2015.xlsx',read_only=True)
ws = wb['Deployment Plan']
x = 4
data = []
for row ws:
for cell in row:
if not cell.value:
python怎么读入excel
print('null')
x = x+1
else:
print(ws['A'+str(x)].value)
data.append(ws['A'+str(x)].value)
x = x+1
print(json.JSONEncoder(data).encode(data))
它只读取第⼀个第⼀个单元格(项⽬1之后还有4个项⽬),然后将所有内容打印为null:
^{pr2}$
它继续⼏个空的结尾是:Traceback (most recent call last):
File "C:\Users\Maynor\Documents\Python\projects\DPprojectlister.py", line 15, in
print(ws['A'+str(x)].value)
File "C:\Python34\lib\site-packages\openpyxl-2.2.\openpyxl\worksheet\worksheet.py", line 400, in __getitem__ return self._get_cell(key)
File "C:\Python34\lib\site-packages\openpyxl-2.2.\openpyxl\worksheet\iter_worksheet.py", line 168, in
_get_cell
cell = _squared_range(col, row, col, row))[0]
IndexError: tuple index out of range
假设在JSON编码的数据到达列的末尾后打印它
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论