首页 > 解决方案 > 我们可以将行和列> 1的数据框复制到Excel工作表中吗?

问题描述

这是我正在使用的代码

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

但我总是收到以下错误: ValueError: ndarray is not C-contiguous

标签: pythonpandaswin32com

解决方案


推荐阅读