赞
踩
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')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。