简体   繁体   English

使用 Python Win32Com 将复制的单元格插入 Excel

[英]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.但是下面的代码给了我一个 Range 类失败错误的 Insert 方法。

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. ws 是从 win32com excel 应用程序中的 Workbooks.Sheets("My Sheet") 获得的。

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"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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