i have been using Python for Finance, by Yves Hilpisch, specifically chapter 12 as a guide to learning how to integrate Excel and Python. I am currently learning how to use OpenPyxl. However the code that i have directly copied from the book isnt working and i keep getting a ValueError. Here is the code that i am using:
#use openpyxl and numpyimport numpy as npimport openpyxl as oxl#create workbook objectwb = oxl.Workbook()#create worksheet objectws = wb.create_sheet(index=0, title='oxl_sheet')#create data arraydata = np.arange(1, 65).reshape((8, 8))#write bulk data to worksheetfor c in range(data.shape[0]): for r in range(data.shape[1]): ws.cell(row=r, column=c).value = data[c, r] # creates a Cell object and assigns a value#save and close workbookwb.save('oxl_book.xlsx')
And here is the error that i am getting:
Traceback (most recent call last):File "test1.py", line 14, in <module>ws.cell(row=r, column=c).value = data[c, r]File "C:\Anaconda2\lib\site-packages\openpyxl\worksheet\worksheet.py", line 307,in cell raise ValueError("Row or column values must be at least 1")ValueError: Row or column values must be at least 1
I am using python 2.7, could that be the problem?I appreciate any and all help.