简体   繁体   中英

Insert copied Cells into Excel with Python Win32Com

The following code will copy the intended range then insert in the intended spot shifting the cells right.

ws.Range("H3:M7).Copy()
ws.Range("H3").Insert()

However I want it to shift the cells down not right. But the following code gives me an Insert method of Range class failed error.

ws.Range("H3:M7).Copy()
ws.Range("H3").Insert(Shift="xlShiftDown")

any suggestions? ws is obtained from Workbooks.Sheets("My Sheet") within the win32com excel application.

Maybe use

ws.Range("H3").Insert(Shift=win32com.client.constants.xlShiftDown)

reference

ws.Range("H3:M7").Select()
excel.Selection.Copy(Destination=workbook.Worksheets("Sheet").Range("H3"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM