Can we copy a dataframe, with rows and cols >1, into an excel sheet?

纵饮孤独 提交于 2020-05-17 14:46:11

问题


Here's the code I am using

excel = win32com.client.Dispatch('Excel.Application')
wb = excel.Workbooks.Open('myWorkbook.xlsx')
df = pd.DataFrame({'A':[1,2,3,4,5], 'B':[11,22,33,44,55], 'C':['a','b','c','d','e']})
wb.Sheets('Template').Copy(Before=None, After=wb.Sheets(wb.Sheets.count))

ws = wb.Sheets(wb.Sheets.count)
ws.Range(ws.cells(40,19), 40+len(df.index)-1, 19+len(df.columns)).Value = df.values

But I always receive the following error: ValueError: ndarray is not C-contiguous

来源:https://stackoverflow.com/questions/61743292/can-we-copy-a-dataframe-with-rows-and-cols-1-into-an-excel-sheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!