当前位置:   article > 正文

Using OpenPyxl_ValueError: Row or column values must be at least 1

valueerror: row or column values must be at least 1
import openpyxl as oxl
wb = oxl.Workbook()
ws = wb.create_sheet(index=0, title='oxl_sheet')
print(data)

for r in range(data.shape[0]):
    for c in range(data.shape[1]):
        ws.cell(row=r, column=c).value =data[r,c]

wb.save(path + 'oxl_book.xlsx')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-139-e9d8583c2e2d> in <module>
      1 for r in range(data.shape[0]):
      2     for c in range(data.shape[1]):
----> 3         ws.cell(row=r, column=c).value =data[r,c]

d:\Anaconda3\lib\site-packages\openpyxl\worksheet\worksheet.py in cell(self, coordinate, row, column, value)
    305 
    306         if row < 1 or column < 1:
--> 307             raise ValueError("Row or column values must be at least 1")
    308 
    309         cell = self._get_cell(row, column)

ValueError: Row or column values must be at least 1

solution:

for r in range(data.shape[0]):
    for c in range(data.shape[1]):
        ws.cell(row=r+1, column=c+1).value =data[r,c]

wb.save(path + 'oxl_book.xlsx')

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

闽ICP备14008679号