我无法复制数据。它在“sel.copy”行给出错误。请帮忙
代码:
excel = client.Dispatch("Excel.Application")
currworkingdirectory = os.getcwd()
workbook = excel.Workbooks.Open(cwd + "\\test.csv")
print (workbook)
excel.Visible = 1
worksheets = workbook.Worksheets(1)
# Copy required data from sheet
sel = worksheets.Range("E:E,H:H,I:I").Select()
sel.Copy()
答案 0 :(得分:1)
worksheets.Range("E:E,H:H,I:I").Select()
不 设置选择"E:E,H:H,I:I"
只选择"E:E,H:H,I:I"
修复变更
sel = worksheets.Range("E:E,H:H,I:I").Select()
到
sel = worksheets.Range("E:E,H:H,I:I")
最后,您最好不要使用复制粘贴,只需设置Range("Destination").Value = sel.Value
即可。